• <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)椴粩嘌莼兊迷絹碓綇?fù)雜。大多數(shù)模式使用時(shí)都會(huì)產(chǎn)生更多更小的類。這使得子系統(tǒng)更具可重用性,也更容易對(duì)子系統(tǒng)進(jìn)行定制,但這也給那些不需要定制子系統(tǒng)的用戶帶來一些使用上的困難。F a c a d e 可以提供一個(gè)簡(jiǎn)單的缺省視圖,這一視圖對(duì)大多數(shù)用戶來說已經(jīng)足夠,而那些需要更多的可定制性的用戶可以越過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)之間是相互依賴的,你可以讓它們僅通過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)在天涯 閱讀(877) 評(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

            搜索

            •  

            積分與排名

            • 積分 - 1808095
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            亚洲精品乱码久久久久久蜜桃图片| 人妻无码精品久久亚瑟影视| 久久中文字幕人妻丝袜| 亚洲一区精品伊人久久伊人| 7777精品久久久大香线蕉| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 久久夜色精品国产噜噜麻豆| 久久久青草青青亚洲国产免观| 色欲综合久久躁天天躁| 粉嫩小泬无遮挡久久久久久| 久久天天躁狠狠躁夜夜2020老熟妇 | 精品久久久久久亚洲| 东方aⅴ免费观看久久av| 99久久国产免费福利| 国产99久久精品一区二区| 久久一日本道色综合久久| 国产亚洲精久久久久久无码AV| 久久99亚洲网美利坚合众国| 国内精品欧美久久精品| 久久精品国产亚洲AV无码娇色| 亚洲人成精品久久久久| 国产巨作麻豆欧美亚洲综合久久| 国内精品伊人久久久久AV影院| 亚洲伊人久久综合影院| 91精品国产综合久久香蕉| 日本欧美久久久久免费播放网| 亚洲国产天堂久久久久久| 久久久久久国产a免费观看不卡| 91久久福利国产成人精品| 中文字幕久久久久人妻| 99精品国产免费久久久久久下载| 久久久久综合中文字幕| 成人精品一区二区久久| 久久夜色精品国产亚洲| 99久久成人国产精品免费| 久久久无码人妻精品无码| 麻豆亚洲AV永久无码精品久久| 午夜精品久久久久久99热| 久久精品国产亚洲av麻豆蜜芽| 国产精品99精品久久免费| 国产亚洲精品自在久久|