blob: 910ee113d70ed82e10462a5eb6d2a95643d1c0d8 (
plain) (
tree)
|
|
#ifndef oo_Register_Implement_H__
#define oo_Register_Implement_H__
#include <map>
#include <vector>
namespace meow{
template<class T>
class ImplementInterface{
private:
T identify_;
protected:
ImplementInterface(T const& id): identify_(id) { }
public:
T const& identify() const { return identify_; }
virtual ~ImplementInterface(){ }
};
//
template<class T>
class RegisterInterface{
private:
std::map<T, ImplementInterface<T>*> implements;
protected:
RegisterInterface();
public:
virtual bool regImplement(ImplementInterface<T>*imp);
virtual ImplementInterface<T>* getImplement(T const& identify);
virtual ~RegisterInterface(){ }
std::vector<T> 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<T>` , and call the constructure with giving
//# `identify` (type `T` ) .
//# * Create an class inherit from `RegisterInterface<T>` ,
//# 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__
|