锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲中文字幕久久精品无码喷水,亚洲国产成人久久一区WWW,日产精品99久久久久久http://m.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://m.shnenglu.com/ztwaker/archive/2008/08/08/58306.html瀛愬脊瀛愬脊Fri, 08 Aug 2008 01:45:00 GMThttp://m.shnenglu.com/ztwaker/archive/2008/08/08/58306.htmlhttp://m.shnenglu.com/ztwaker/comments/58306.htmlhttp://m.shnenglu.com/ztwaker/archive/2008/08/08/58306.html#Feedback0http://m.shnenglu.com/ztwaker/comments/commentRss/58306.htmlhttp://m.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://m.shnenglu.com/ztwaker/archive/2008/07/17/56419.html瀛愬脊瀛愬脊Thu, 17 Jul 2008 04:43:00 GMThttp://m.shnenglu.com/ztwaker/archive/2008/07/17/56419.htmlhttp://m.shnenglu.com/ztwaker/comments/56419.htmlhttp://m.shnenglu.com/ztwaker/archive/2008/07/17/56419.html#Feedback0http://m.shnenglu.com/ztwaker/comments/commentRss/56419.htmlhttp://m.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://m.shnenglu.com/ztwaker/archive/2008/07/04/55358.html瀛愬脊瀛愬脊Fri, 04 Jul 2008 09:36:00 GMThttp://m.shnenglu.com/ztwaker/archive/2008/07/04/55358.htmlhttp://m.shnenglu.com/ztwaker/comments/55358.htmlhttp://m.shnenglu.com/ztwaker/archive/2008/07/04/55358.html#Feedback0http://m.shnenglu.com/ztwaker/comments/commentRss/55358.htmlhttp://m.shnenglu.com/ztwaker/services/trackbacks/55358.html
Key point: 澶у眬鎬濇兂 鍒嗗眰鎬濇兂

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

瀛愬脊 2008-07-04 17:36 鍙戣〃璇勮
]]>
久久亚洲国产成人影院网站 | 久久久亚洲裙底偷窥综合| 久久久久99精品成人片牛牛影视| 亚洲综合久久综合激情久久| 99久久国产综合精品网成人影院 | 久久精品无码一区二区三区免费| 久久影视国产亚洲| 久久久久久久久无码精品亚洲日韩| 久久96国产精品久久久| 人妻精品久久久久中文字幕| 99国产精品久久| 久久人人爽人人爽人人av东京热| 久久精品国产99国产电影网| 香蕉aa三级久久毛片| 国产精品久久久久aaaa| 国产一区二区久久久| 久久久久久久综合综合狠狠| 久久香综合精品久久伊人| 香蕉久久久久久狠狠色| 国产成人精品久久亚洲| 久久丫精品国产亚洲av不卡| 久久久精品国产| 久久久久亚洲AV综合波多野结衣| 国产精品久久久久久久| 亚洲精品乱码久久久久久蜜桃图片| 久久黄视频| 久久99亚洲综合精品首页| 久久99精品综合国产首页| 午夜精品久久久久久毛片| 超级97碰碰碰碰久久久久最新| 国产ww久久久久久久久久| 热re99久久精品国产99热| 狠狠色丁香久久综合五月| 久久久亚洲AV波多野结衣 | 99久久做夜夜爱天天做精品| 久久精品无码免费不卡| 青青草原综合久久大伊人导航| 国内精品久久久久久久久电影网 | 香蕉久久夜色精品国产小说| 国产精品久久久久9999高清| 99久久久精品免费观看国产|