#ifndef oo_Register_Implement_H__ #define oo_Register_Implement_H__ #include #include namespace meow{ template class ImplementInterface{ private: T identify_; protected: ImplementInterface(T const& id): identify_(id) { } public: T const& identify() const { return identify_; } virtual ~ImplementInterface(){ } }; // template class RegisterInterface{ private: std::map*> implements; protected: RegisterInterface(); public: virtual bool regImplement(ImplementInterface*imp); virtual ImplementInterface* getImplement(T const& identify); virtual ~RegisterInterface(){ } std::vector getIdentifys() const; }; //# //# === meow:: *ImplementInterface/RegisterInterface* (C++ Class) //# ==== Description //# Assume there is a problem which can be solved by different algorithms. //# Then you can write multiple classes to approach this problem. + //# Now if you want to decide which algorithm to use in runtime, you can just //# approach this case by a simple way: //# //# * Let all the problem-solving classes inherit from //# `class ImplementInterface` , and call the constructure with giving //# `identify` (type `T` ) . //# * Create an class inherit from `RegisterInterface` , //# and register all your implement class to it by call //# `regImplement(pointer to the class)`. //# * Select which implement class you want by call //# `getImplement(identify)` , which will return the pointer //# to the corresponding class. //# //# ''' //# } #include "Register_Implement.hpp" #endif // oo_Register_Implement_H__