• <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>

            C++ Programmer's Cookbook

            {C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

            模式設(shè)計(jì)c#--結(jié)構(gòu)型--facade

            名稱 Facade
            結(jié)構(gòu) o_facade.bmp
            意圖 為子系統(tǒng)中的一組接口提供一個(gè)一致的界面,F(xiàn) a c a d e 模式定義了一個(gè)高層接口,這個(gè)接口使得這一子系統(tǒng)更加容易使用。
            適用性
            • 當(dāng)你要為一個(gè)復(fù)雜子系統(tǒng)提供一個(gè)簡(jiǎn)單接口時(shí)。子系統(tǒng)往往因?yàn)椴粩嘌莼兊迷絹?lái)越復(fù)雜。大多數(shù)模式使用時(shí)都會(huì)產(chǎn)生更多更小的類。這使得子系統(tǒng)更具可重用性,也更容易對(duì)子系統(tǒng)進(jìn)行定制,但這也給那些不需要定制子系統(tǒng)的用戶帶來(lái)一些使用上的困難。F a c a d e 可以提供一個(gè)簡(jiǎn)單的缺省視圖,這一視圖對(duì)大多數(shù)用戶來(lái)說(shuō)已經(jīng)足夠,而那些需要更多的可定制性的用戶可以越過(guò)f a c a d e 層。
            • 客戶程序與抽象類的實(shí)現(xiàn)部分之間存在著很大的依賴性。引入f a c a d e 將這個(gè)子系統(tǒng)與客戶以及其他的子系統(tǒng)分離,可以提高子系統(tǒng)的獨(dú)立性和可移植性。
            • 當(dāng)你需要構(gòu)建一個(gè)層次結(jié)構(gòu)的子系統(tǒng)時(shí),使用f a c a d e 模式定義子系統(tǒng)中每層的入口點(diǎn)。如果子系統(tǒng)之間是相互依賴的,你可以讓它們僅通過(guò)f a c a d e 進(jìn)行通訊,從而簡(jiǎn)化了它們之間的依賴關(guān)系。

            Code Example
            namespace?Facade_DesignPattern
            {
            ????
            using?System;

            ????
            class?SubSystem_class1?
            ????
            {
            ????????
            public?void?OperationX()?
            ????????
            {
            ????????????Console.WriteLine(
            "SubSystem_class1.OperationX?called");
            ????????}

            ????}


            ????
            class?SubSystem_class2
            ????
            {
            ????????
            public?void?OperationY()
            ????????
            {
            ????????????Console.WriteLine(
            "SubSystem_class2.OperationY?called");
            ????????}

            ????}


            ????
            class?SubSystem_class3?
            ????
            {
            ????????
            public?void?OperationZ()
            ????????
            {????????????
            ????????????Console.WriteLine(
            "SubSystem_class3.OperationZ?called");
            ????????}
            ????
            ????}


            ????
            class?Facade?
            ????
            {
            ????????
            private?SubSystem_class1?c1?=?new?SubSystem_class1();
            ????????
            private?SubSystem_class2?c2?=?new?SubSystem_class2();
            ????????
            private?SubSystem_class3?c3?=?new?SubSystem_class3();

            ????????
            public?void?OperationWrapper()
            ????????
            {
            ????????????Console.WriteLine(
            "The?Facade?OperationWrapper?carries?out?complex?decision-making");
            ????????????Console.WriteLine(
            "which?in?turn?results?in?calls?to?the?subsystem?classes");
            ????????????c1.OperationX();
            ????????????
            if?(1==1?/*some?really?complex?decision*/)
            ????????????
            {
            ????????????????c2.OperationY();
            ????????????}

            ????????????
            //?lots?of?complex?code?here?.?.?.
            ????????????c3.OperationZ();
            ????????}

            ????????
            ????}


            ????
            ///?<summary>
            ????
            ///????Summary?description?for?Client.
            ????
            ///?</summary>

            ????public?class?Client
            ????
            {
            ??????????
            public?static?int?Main(string[]?args)
            ????????
            {
            ????????????Facade?facade?
            =?new?Facade();
            ????????????Console.WriteLine(
            "Client?calls?the?Facade?OperationWrapper");
            ????????????facade.OperationWrapper();??????
            ????????????
            return?0;
            ????????}

            ????}

            }


            一個(gè)實(shí)際生活的例子:
            //?Facade?pattern?--?Real?World?example??


            using?System;

            namespace?DoFactory.GangOfFour.Facade.RealWorld
            {
            ??
            //?MainApp?test?application?

            ??
            class?MainApp
            ??
            {
            ????
            static?void?Main()
            ????
            {
            ??????
            //?Facade?
            ??????Mortgage?mortgage?=?new?Mortgage();

            ??????
            //?Evaluate?mortgage?eligibility?for?customer?
            ??????Customer?customer?=?new?Customer("Ann?McKinsey");
            ??????
            bool?eligable?=?mortgage.IsEligible(customer,125000);
            ??????
            ??????Console.WriteLine(
            "\n"?+?customer.Name?+?
            ??????????
            "?has?been?"?+?(eligable???"Approved"?:?"Rejected"));

            ??????
            //?Wait?for?user?
            ??????Console.Read();
            ????}

            ??}


            ??
            //?"Subsystem?ClassA"?

            ??
            class?Bank
            ??
            {
            ????
            public?bool?HasSufficientSavings(Customer?c,?int?amount)
            ????
            {
            ??????Console.WriteLine(
            "Check?bank?for?"?+?c.Name);
            ??????
            return?true;
            ????}

            ??}


            ??
            //?"Subsystem?ClassB"?

            ??
            class?Credit
            ??
            {
            ????
            public?bool?HasGoodCredit(Customer?c)
            ????
            {
            ??????Console.WriteLine(
            "Check?credit?for?"?+?c.Name);
            ??????
            return?true;
            ????}

            ??}


            ??
            //?"Subsystem?ClassC"?

            ??
            class?Loan
            ??
            {
            ????
            public?bool?HasNoBadLoans(Customer?c)
            ????
            {
            ??????Console.WriteLine(
            "Check?loans?for?"?+?c.Name);
            ??????
            return?true;
            ????}

            ??}


            ??
            class?Customer
            ??
            {
            ????
            private?string?name;

            ????
            //?Constructor?
            ????public?Customer(string?name)
            ????
            {
            ??????
            this.name?=?name;
            ????}


            ????
            //?Property?
            ????public?string?Name
            ????
            {
            ??????
            get{?return?name;?}
            ????}

            ??}


            ??
            //?"Facade"?

            ??
            class?Mortgage
            ??
            {
            ????
            private?Bank?bank?=?new?Bank();
            ????
            private?Loan?loan?=?new?Loan();
            ????
            private?Credit?credit?=?new?Credit();

            ????
            public?bool?IsEligible(Customer?cust,?int?amount)
            ????
            {
            ??????Console.WriteLine(
            "{0}?applies?for?{1:C}?loan\n",
            ????????cust.Name,?amount);

            ??????
            bool?eligible?=?true;

            ??????
            //?Check?creditworthyness?of?applicant?
            ??????if?(!bank.HasSufficientSavings(cust,?amount))?
            ??????
            {
            ????????eligible?
            =?false;
            ??????}

            ??????
            else?if?(!loan.HasNoBadLoans(cust))?
            ??????
            {
            ????????eligible?
            =?false;
            ??????}

            ??????
            else?if?(!credit.HasGoodCredit(cust))?
            ??????
            {
            ????????eligible?
            =?false;
            ??????}


            ??????
            return?eligible;
            ????}

            ??}

            }
            ?
            Output
            MethodA() ----
            SubSystemOne Method
            SubSystemTwo Method
            SubSystemFour Method

            MethodB() ----
            SubSystemTwo Method
            SubSystemThree Method

            posted on 2006-01-03 15:48 夢(mèng)在天涯 閱讀(876) 評(píng)論(1)  編輯 收藏 引用 所屬分類: Design pattern

            評(píng)論

            # re: 模式設(shè)計(jì)c#--結(jié)構(gòu)型--facade 2006-04-24 15:17 夢(mèng)在天涯

            在什么情況下使用門面模式
            為一個(gè)復(fù)雜子系統(tǒng)提供一個(gè)簡(jiǎn)單接口
            提高子系統(tǒng)的獨(dú)立性
            在層次化結(jié)構(gòu)中,可以使用Facade模式定義系統(tǒng)中每一層的入口。
              回復(fù)  更多評(píng)論   

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計(jì)

            • 隨筆 - 461
            • 文章 - 4
            • 評(píng)論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1807577
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            天天久久狠狠色综合| 久久精品国产男包| 亚洲AV日韩精品久久久久久| 超级碰久久免费公开视频| 国内精品久久久久久久97牛牛| 99久久国产亚洲综合精品| 久久亚洲中文字幕精品一区| 国内精品伊人久久久久影院对白| 热re99久久精品国产99热| 久久国产精品久久久| 久久精品国产一区| 日本精品久久久中文字幕| 亚洲国产二区三区久久| 久久精品国产一区二区三区 | 午夜精品久久久久久久久| 久久精品中文字幕一区| 久久综合给合久久狠狠狠97色| 日韩人妻无码一区二区三区久久 | 97精品依人久久久大香线蕉97| 久久91精品国产91| 久久久久人妻一区二区三区| 久久久无码精品亚洲日韩按摩 | 精品国产福利久久久| 久久不见久久见免费影院www日本| 国产午夜精品久久久久九九| 亚洲а∨天堂久久精品| 久久久久亚洲AV片无码下载蜜桃| 97久久精品无码一区二区天美| 狠狠人妻久久久久久综合| 久久夜色精品国产噜噜亚洲a| 久久精品九九亚洲精品| 久久久久国色AV免费看图片| 99久久无色码中文字幕人妻| 国产精品一区二区久久| 久久精品极品盛宴观看| 国产综合免费精品久久久| 亚洲乱码中文字幕久久孕妇黑人| 亚洲综合久久综合激情久久| A级毛片无码久久精品免费| 26uuu久久五月天| 久久国产乱子伦免费精品|