• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            蝸牛的家
            男兒當(dāng)自強
            posts - 48,  comments - 21,  trackbacks - 0
            意圖:
            用原型指定創(chuàng)建對象的種類,并且通過拷貝函數(shù)用這些原型創(chuàng)建對象
            適用:
            當(dāng)要實例化的類是在運行時刻指定時,例如:通過動態(tài)裝載
            為了避免創(chuàng)建一個與產(chǎn)品類層次平行的工廠類層次時
            當(dāng)一個類的實例只能有幾個不同狀態(tài)組合中的一種時,建立相應(yīng)數(shù)目的原型并克隆可能要更方便些
            UML圖:

            解析:Prototype類似車輛的展示,當(dāng)你喜歡某款車時,他們會給你一款相同款式的車,像軟件中的復(fù)制,而不是車展的那輛
            //test.h
            //////////////////////////////////////////////////////////////////////////
            //虛基類,提供基本函數(shù)
            class Prototype
            {
            public:
                Prototype()
            {}
                
            virtual ~Prototype(){}
                
            virtual Prototype* Clone() = 0;
            }
            ;

            //派生出來的類,實現(xiàn)具體的Clone函數(shù)
            class ConCreatePrototype1 : public Prototype
            {
            public:
                ConCreatePrototype1();
                ConCreatePrototype1(
            const ConCreatePrototype1&); //拷貝構(gòu)造函數(shù),通過這個函數(shù)實現(xiàn)類的復(fù)制
                ~ConCreatePrototype1();
                
                
            virtual Prototype* Clone(); //復(fù)制出相同對象的接口
            }
            ;


            // test.cpp : Defines the entry point for the console application.
            //

            #include 
            "stdafx.h"
            #include 
            <iostream>
            #include 
            "stdlib.h"
            #include 
            "test.h"

            using namespace std;
            //////////////////////////////////////////////////////////////////////////
            ConCreatePrototype1::ConCreatePrototype1()
            {
                cout 
            << "construction of ConCreatePrototype1\n";
            }

            ConCreatePrototype1::
            ~ConCreatePrototype1()
            {
                cout 
            << "destruction of ConCreatePrototype1\n";
            }

            ConCreatePrototype1::ConCreatePrototype1(
            const ConCreatePrototype1&)
            {
                cout 
            << "copy a same object as ConCreatePrototype1\n";
            }

            Prototype
            * ConCreatePrototype1::Clone()
            {
                
            return new ConCreatePrototype1(*this);
            }

            //////////////////////////////////////////////////////////////////////////
            int main(int argc, char* argv[])
            {
                Prototype
            * pPrototype = new ConCreatePrototype1;
                Prototype
            * pPrototype2 = pPrototype->Clone();

                delete pPrototype;
                delete pPrototype2;
                
                system(
            "pause");
                
            return 0;
            }

            posted on 2008-08-17 01:16 黑色天使 閱讀(545) 評論(0)  編輯 收藏 引用 所屬分類: 設(shè)計模式

            <2008年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久伊人中文无码| 久久久久亚洲精品天堂| 久久久久久极精品久久久| 久久久久国产亚洲AV麻豆| 久久久久久久国产免费看| 99久久免费国产精品特黄| 久久精品午夜一区二区福利| 久久se精品一区二区影院 | 色天使久久综合网天天| 亚洲精品乱码久久久久久自慰| 97久久超碰成人精品网站| 狠狠精品干练久久久无码中文字幕| 欧美激情精品久久久久久久 | 久久精品视频免费| 亚洲午夜无码AV毛片久久| 久久99精品综合国产首页| 亚洲国产日韩综合久久精品| 久久av无码专区亚洲av桃花岛| 久久一本综合| 久久精品一区二区三区中文字幕| 久久精品99久久香蕉国产色戒 | 久久人人添人人爽添人人片牛牛 | 色播久久人人爽人人爽人人片aV| 91久久婷婷国产综合精品青草| 中文字幕无码av激情不卡久久| 99久久久久| 久久久精品免费国产四虎| 99久久超碰中文字幕伊人 | 99久久国产免费福利| 久久久精品午夜免费不卡| 国产精品美女久久久久网| 久久久久亚洲av无码专区导航 | 久久婷婷国产综合精品| 色狠狠久久AV五月综合| 久久亚洲精品国产精品| 久久午夜伦鲁片免费无码| 久久99国产综合精品免费| 国产成人久久精品一区二区三区 | 99久久精品日本一区二区免费| 国产情侣久久久久aⅴ免费| 久久精品国产亚洲av高清漫画 |