锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品狼人久久久久影院,久久笫一福利免费导航 ,久久99亚洲网美利坚合众国http://www.shnenglu.com/ztwaker/category/7242.html<font color=#FF0000>/* 鎺屾彙鏈潵鏈澶х殑瓚嬪娍錛氫俊鎭寲銆佽嚜鍔ㄥ寲銆佷竴浣撳寲銆佷漢鎬у寲 */ </font><font color=#00FF00>[緇堥渶鏈夋棩榫欑┛鍑?鍞斾嬌鏃ユ棩瑁ょ┛紿縘</font>zh-cnFri, 08 Aug 2008 05:06:07 GMTFri, 08 Aug 2008 05:06:07 GMT60[璁捐妯″紡] 涓婄彮璺笂紿佺劧鎯沖埌鐨刡uilder妯″紡http://www.shnenglu.com/ztwaker/archive/2008/08/08/58306.html瀛愬脊瀛愬脊Fri, 08 Aug 2008 01:45:00 GMThttp://www.shnenglu.com/ztwaker/archive/2008/08/08/58306.htmlhttp://www.shnenglu.com/ztwaker/comments/58306.htmlhttp://www.shnenglu.com/ztwaker/archive/2008/08/08/58306.html#Feedback0http://www.shnenglu.com/ztwaker/comments/commentRss/58306.htmlhttp://www.shnenglu.com/ztwaker/services/trackbacks/58306.html
Only some thinking to help to think about the Builder Pattern, but it's not so intuitive.
Suppose that we want to save data to files.

class File { /*abstract file*/ };
class FileBuilder
{
public:
    virtual bool buildFileHeader() =0;
    virtual bool buildFileBody()   =0;
    virtual bool buildFileTail()   =0;
    virtual File* getFile()        =0;
};
 
class BmpFile  : public File { .... };
class GifFile  : public File { .... };
class JpegFile : public File { .... };
//other kinds of files
 
class BmpFileBuilder : public FileBuilder
{
};
 
class GifFileBuilder : public FileBuilder
{
};
 
class JpegFileBuilder : public FileBuilder
{
};
//builders above implement those interfaces from FileBuilder
//other kinds of file builders

 
//usage
File* buildFile(FileBuilder* fb)
{
    fb.buildFileHeader();
    fb.buildFileBody();
    fb.buildFileTail();
    return fb.GetFile();
}
void func()
{
    FileBuilder* fb = new SomeFileBuilder();
    File* f = buildFile(fb);
    //use f
    ....
}
 
Key Points:
1. Each builder is responsible for its buildXXX()
2. Each builder builds one kind of File
3. the File would be created in builder's constructor



瀛愬脊 2008-08-08 09:45 鍙戣〃璇勮
]]>
[璁捐妯″紡] Understand Design Patterns -- Factory Methodhttp://www.shnenglu.com/ztwaker/archive/2008/07/17/56419.html瀛愬脊瀛愬脊Thu, 17 Jul 2008 04:43:00 GMThttp://www.shnenglu.com/ztwaker/archive/2008/07/17/56419.htmlhttp://www.shnenglu.com/ztwaker/comments/56419.htmlhttp://www.shnenglu.com/ztwaker/archive/2008/07/17/56419.html#Feedback0http://www.shnenglu.com/ztwaker/comments/commentRss/56419.htmlhttp://www.shnenglu.com/ztwaker/services/trackbacks/56419.htmlFactory Method

// interface
class People
{
public:
    virtual void doWhat() =0;
    virtual string type() const =0;
};

class Male : public People
{
public:
    virtual void doWhat();
    virtual string type() const;
    static  People* creator();
};

class Female : public People
{
public:
    virtual void doWhat();
    virtual string type() const;
    static  People* creator();
};


// interface
typedef People* (*CreateFcn)();
class PeopleFactory
{
public:
    static People* producePeople(const string& type);
    static addCreateFcn(const string& type, CreateFcn creator);

private:
    static map<string, CreateFcn> createFcns;
};

People* PeopleFactory::producePeople(const string& type)
{
    //***1
    CreateFcn creator= createFcns[type];
    return creator();
}

---- test ----
void f()
{
    //***2
    const string t("Male"); //or "Female"
    People* p = PeopleFactory::producePeople(t);
    p->doWhat();   
    delete p;
}

---- extension ----
class Hemophrodite : public People
{
    virtual void doWhat();
    virtual string type() const;
    static  People* creator();
};

void g()
{
    //***3
    const string newType = "Hemophrodite";
    PeopleFactory::addCreateFcn(newType, Hemophrodite::creator);

    // usage
    const string t("Hemophrodite");
    People* p = PeopleFactory::producePeople(t);
    p->doWhat();   
    delete p;
}

Cool!! OCP!!

---------
Key point:

1. How does the Factory Method create the instance
    of classes through their type names?
   How could this method follow the OCP?

2. Where does the type name come from?
 -- config file
 -- registry
 -- other method

3. About extension
  
----------
Interface classes:
    People & PeopleFactory


enjoy it!!

瀛愬脊 2008-07-17 12:43 鍙戣〃璇勮
]]>
[緇忛獙鏁欒] 璁捐瑕佺偣http://www.shnenglu.com/ztwaker/archive/2008/07/04/55358.html瀛愬脊瀛愬脊Fri, 04 Jul 2008 09:36:00 GMThttp://www.shnenglu.com/ztwaker/archive/2008/07/04/55358.htmlhttp://www.shnenglu.com/ztwaker/comments/55358.htmlhttp://www.shnenglu.com/ztwaker/archive/2008/07/04/55358.html#Feedback0http://www.shnenglu.com/ztwaker/comments/commentRss/55358.htmlhttp://www.shnenglu.com/ztwaker/services/trackbacks/55358.html
Key point: 澶у眬鎬濇兂 鍒嗗眰鎬濇兂

璁捐錛屾湁寰堝鏂規(guī)硶銆備笉綆″摢縐嶆柟娉曪紝閮介渶瑕佸寰呰璁$殑瀵硅薄鐨勬繁鍏ョ殑浜嗚В銆?br>
瑕佹湁澶у眬鎬濇兂錛屼笉鑳界涓璞癸紝瑙佹湪涓嶈鏋椼?br>
璁捐鏃訛紝涓嶈兘榪囧鑰冭檻緇嗚妭銆傚鏋滈櫡鍦ㄧ粏鑺傞噷錛岃鍙?qiáng)鏃朵腑姝㈠拰閫鍑恒?br>
鑷笂鑰屼笅錛屽眰灞傜粏鍖栨槸涓縐嶄笉閿欑殑鏂規(guī)硶銆?br>
鍙互鍊熺敤涓涓嬪浘褰㈠涓殑“鍒嗗眰嬈$粏鑺傛ā鍨?#8221;銆?br>
涓嶅悓鐨勫眰嬈″簲璇ユ湁涓嶅悓鐨勭粏鑺傘?br>
緇撴瀯鍖栨湁鍔╀簬鎬濊礬娓呮櫚鍖栥傛爲(wèi)鍨嬬粨鏋勬槸涓縐嶄笉閿欑殑閫夋嫨銆?br>
姣忎釜闃舵鍙仛濂介偅涓樁孌電殑浜嬶紝鍏朵粬鐨勪簨涓寰嬩笉鑳藉仛錛堝敖綆¤兘鍋氭瀬濂戒篃涓嶈錛夈?br>
澶氬拰浜鴻璁哄績涓殑鎯蟲硶銆傚娉ㄦ剰鍒漢鐨勬濊礬錛屼笌宸叉瘮杈冿紝鍙栭暱琛ョ煭銆?br>
閫氬父錛屽浜庨棶棰橈紝瓚婅璁鴻秺娓呮櫚銆?

瀛愬脊 2008-07-04 17:36 鍙戣〃璇勮
]]>
一本色道久久综合狠狠躁篇| 久久免费小视频| 亚洲人成网站999久久久综合 | 合区精品久久久中文字幕一区| 91秦先生久久久久久久| 亚洲精品99久久久久中文字幕| 99久久国产亚洲综合精品| 久久久无码精品亚洲日韩蜜臀浪潮| 国内精品伊人久久久久| 免费一级做a爰片久久毛片潮| 一本色道久久88精品综合| 99久久综合国产精品二区| 久久久无码精品亚洲日韩蜜臀浪潮 | 99麻豆久久久国产精品免费| 久久久久国产一区二区三区| 久久久久久九九99精品| 中文字幕无码久久人妻| 88久久精品无码一区二区毛片 | 久久国产三级无码一区二区| 久久久久久精品久久久久| 99久久精品无码一区二区毛片| 99久久国产精品免费一区二区| 久久国产成人午夜aⅴ影院| 狠狠88综合久久久久综合网| 中文字幕热久久久久久久| 久久久国产一区二区三区| 久久婷婷综合中文字幕| 久久综合噜噜激激的五月天| 少妇无套内谢久久久久| 99久久人人爽亚洲精品美女| 国产精品岛国久久久久| 99re这里只有精品热久久| 日韩精品无码久久久久久| 伊人久久大香线蕉综合Av| 狠狠色婷婷久久一区二区| 亚洲va久久久久| 中文字幕久久亚洲一区| 亚洲国产成人久久综合野外| 色婷婷噜噜久久国产精品12p | 2021精品国产综合久久| 久久久久久国产精品免费无码|