Design Pattern --- Factory Method

class Document {};
class MyDocument : public Document {};

class Application
{
public:
    virtual Document *CreateDocument() = 0;
};
class MyApplication : public Application
{
public:
    virtual Document *CreateDocument() override
    {
        return new MyDocument;
    }
};

其中, CreateDocument 就是 Factory Method.

主要意图就是将实例化的时机延后到子类.

posted @ 2013-02-16 09:43  walfud  阅读(117)  评论(0编辑  收藏  举报