設計模式-Factory模式戲說

來源:互聯網
上載者:User

設計模式-Factory模式戲說

1。利用抽象基類繼承的方式,和抽象基類之間的從屬關係來構造整個系統,達到一個相對清晰的類層次關係。

2。保持整個系統的可擴充和最低的維護成本。

我說清楚了嗎?上碼,^_^。

///////////////////////////////////////////////////////////////

class 飛彈
{
  public:
    vitrual ~飛彈();
 
  protected:
        飛彈();
}
//------------------------------------------------------------
class 地對空飛彈 :public 飛彈
{
   public:
    地對空飛彈();
    ~地對空飛彈();
}

class 反導防禦:public 飛彈
{
  public:
      反導防禦();
      ~反導防禦();
}

/////////////////////////////////////////////////////////////
class 車軲轆
{
   public:
    vitrual ~車軲轆();
 
  protected:
        車軲轆();
}
//-------------------------------------------------
class 韓國車軲轆 :public 車軲轆
{
   public:
    韓國車軲轆();
      ~韓國車軲轆();
}

class 東風車軲轆 :public 車軲轆
{
   public:
    東風車軲轆();
      ~東風車軲轆();
}

/////////////////////////////////////////////////////////////////
class 輪胎
{
   public:
    vitrual ~輪胎();
 
  protected:
        輪胎();
}
//---------------------------------------------
class 米琪琳 :pubilc 輪胎
{
   public:
    米琪琳();
      ~米琪琳();
}

class 吉利 :pubilc 輪胎
{
   public:
    吉利();
      ~吉利();
}
//////////////////////////////////////////////////////////////////

class 汽車
{
  public:
    vitrual ~汽車();

    virtual 輪胎* 輪胎()const  {return new 輪胎;}
    virtual 車軲轆* 車軲轆()const  {return new 車軲轆;}
    virtual 飛彈* 飛彈()const  {return new 飛彈;}

  protected:
    汽車();
}

class 我的車 : public 汽車
{
 public:
   我的車();
   ~我的車();

   virtual 輪胎* 輪胎()const  {return new 吉利;}
   virtual 車軲轆* 車軲轆()const  {return new 東風車軲轆;}
   virtual 飛彈* 飛彈()const  {return new 地對空飛彈;}
}

class 老婆的車 : public 汽車
{
  public:
    老婆的車();
   ~老婆的車();

    virtual 輪胎* 輪胎()const  {return new 米琪琳;}
   virtual 車軲轆* 車軲轆()const  {return new 韓國車軲轆;}
   virtual 飛彈* 飛彈()const  {return new 反導防禦;}
}

class 童車 : public 汽車
{
  public:
   童車();
   ~童車();

   virtual 輪胎* 輪胎()const  {return new 吉利;}
   virtual 車軲轆* 車軲轆()const  {return new 東風車軲轆;}
   virtual 飛彈* 飛彈()const  {return new 反導防禦;}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.