
package provide xotcl::pattern::manager 1.0
package require XOTcl 1

namespace eval ::xotcl::pattern::manager {
    namespace import ::xotcl::*

    #
    # a simle manager pattern following buschmann (164) 
    # based on dynamic object aggregation and using dynamic code
    # for supplier creation (instead of loading)
    #
    # it shares the suppliers !
    #

    #
    # abstract supplier, init starts dynamic code creation
    #
    Class Supplier
    Supplier abstract instproc init args
    Supplier abstract instproc m args


    Class Manager -parameter {
	{supplierClass Supplier}
    } 

    Manager instproc getSupplier {name} {
	if {[my info children [namespace tail $name]] != ""} {
	    return [self]::[namespace tail $name]
	} else {
	    return [my [my supplierClass] [namespace tail $name]]
	}
    }

    namespace export Supplier Manager
}

namespace import ::xotcl::pattern::manager::*
