ホーム > DesignPattern > Factory
ファクトリー
ファクトリークラス
class DataObject { public: const static int READ = 0; const static int WRITE = 1; const static int APPEND = 2; static DataObject* create(int type, string file); virtual string OpenMode(int id) = 0; }; DataObject* DataObject::create(int type, string file) { DataObject* result; switch(type) { case READ: result = new ReadFileDataObject(file); break; case WRITE: result = new WriteFileDataObject(file); break; case APPEND: result = new AppendFileDataObject(file); break; } return result; }
このページのURL: