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.

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

相关文章:

  • 2021-09-06
  • 2021-11-05
  • 2022-01-20
  • 2022-02-07
  • 2022-02-27
  • 2021-07-25
  • 2022-02-10
猜你喜欢
  • 2021-11-20
  • 2022-01-24
  • 2021-08-12
  • 2022-12-23
  • 2021-12-19
  • 2021-11-22
相关资源
相似解决方案