--- trunk/tengDissertation/Appendix.tex 2006/06/08 06:39:37 2821 +++ trunk/tengDissertation/Appendix.tex 2006/06/08 07:27:56 2822 @@ -166,27 +166,19 @@ implemented by delegating the creation operation to th with the problem of creating objects without specifying the exact class of object that will be created. Factory Method is typically implemented by delegating the creation operation to the subclasses. + +Registers a creator with a type identifier. Looks up the type +identifier in the internal map. If it is found, it invokes the +corresponding creator for the type identifier and returns its +result. \begin{lstlisting}[float,caption={[].},label={appendixScheme:factoryDeclaration}] class IntegratorCreator; class IntegratorFactory { public: typedef std::map CreatorMapType; - /** - * Registers a creator with a type identifier - * @return true if registration is successful, otherwise return false - * @id the identification of the concrete object - * @creator the object responsible to create the concrete object - */ bool registerIntegrator(IntegratorCreator* creator); - /** - * Looks up the type identifier in the internal map. If it is found, it invokes the - * corresponding creator for the type identifier and returns its result. - * @return a pointer of the concrete object, return NULL if no creator is registed for - * creating this concrete object - * @param id the identification of the concrete object - */ Integrator* createIntegrator(const std::string& id, SimInfo* info); private: @@ -199,7 +191,8 @@ implemented by delegating the creation operation to th return creatorMap_.erase(id) == 1; } - Integrator* IntegratorFactory::createIntegrator(const std::string& id, SimInfo* info) { + Integrator* + IntegratorFactory::createIntegrator(const std::string& id, SimInfo* info) { CreatorMapType::iterator i = creatorMap_.find(id); if (i != creatorMap_.end()) { //invoke functor to create object @@ -215,7 +208,7 @@ implemented by delegating the creation operation to th class IntegratorCreator { public: IntegratorCreator(const std::string& ident) : ident_(ident) {} - virtual ~IntegratorCreator() {} + const std::string& getIdent() const { return ident_; } virtual Integrator* create(SimInfo* info) const = 0; @@ -228,7 +221,9 @@ implemented by delegating the creation operation to th class IntegratorBuilder : public IntegratorCreator { public: IntegratorBuilder(const std::string& ident) : IntegratorCreator(ident) {} - virtual Integrator* create(SimInfo* info) const {return new ConcreteIntegrator(info);} + virtual Integrator* create(SimInfo* info) const { + return new ConcreteIntegrator(info); + } }; \end{lstlisting}