• <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++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            模式設計c#--結構型--facade

            名稱 Facade
            結構 o_facade.bmp
            意圖 為子系統中的一組接口提供一個一致的界面,F a c a d e 模式定義了一個高層接口,這個接口使得這一子系統更加容易使用。
            適用性
            • 當你要為一個復雜子系統提供一個簡單接口時。子系統往往因為不斷演化而變得越來越復雜。大多數模式使用時都會產生更多更小的類。這使得子系統更具可重用性,也更容易對子系統進行定制,但這也給那些不需要定制子系統的用戶帶來一些使用上的困難。F a c a d e 可以提供一個簡單的缺省視圖,這一視圖對大多數用戶來說已經足夠,而那些需要更多的可定制性的用戶可以越過f a c a d e 層。
            • 客戶程序與抽象類的實現部分之間存在著很大的依賴性。引入f a c a d e 將這個子系統與客戶以及其他的子系統分離,可以提高子系統的獨立性和可移植性。
            • 當你需要構建一個層次結構的子系統時,使用f a c a d e 模式定義子系統中每層的入口點。如果子系統之間是相互依賴的,你可以讓它們僅通過f a c a d e 進行通訊,從而簡化了它們之間的依賴關系。

            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;
            ????????}

            ????}

            }


            一個實際生活的例子:
            //?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 夢在天涯 閱讀(872) 評論(1)  編輯 收藏 引用 所屬分類: Design pattern

            評論

            # re: 模式設計c#--結構型--facade 2006-04-24 15:17 夢在天涯

            在什么情況下使用門面模式
            為一個復雜子系統提供一個簡單接口
            提高子系統的獨立性
            在層次化結構中,可以使用Facade模式定義系統中每一層的入口。
              回復  更多評論   

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804603
            • 排名 - 5

            最新評論

            閱讀排行榜

            久久国产劲爆AV内射—百度| 久久精品国产99久久丝袜| Xx性欧美肥妇精品久久久久久| 国产69精品久久久久久人妻精品| 久久久久噜噜噜亚洲熟女综合| 日本精品久久久久中文字幕| 国产91色综合久久免费| 好久久免费视频高清| 99久久久国产精品免费无卡顿| 色偷偷偷久久伊人大杳蕉| 天天躁日日躁狠狠久久| 奇米综合四色77777久久| 久久精品aⅴ无码中文字字幕不卡| 久久久久亚洲av无码专区喷水| 狠狠色丁香久久婷婷综合五月| 国内精品伊人久久久久av一坑| 成人妇女免费播放久久久| 9久久9久久精品| 久久久久婷婷| 囯产极品美女高潮无套久久久| 精品少妇人妻av无码久久| 久久精品9988| 亚洲精品无码久久毛片| 久久无码人妻一区二区三区午夜| 91精品国产9l久久久久| 99久久婷婷国产综合精品草原| 久久久久一本毛久久久| 久久国产劲爆AV内射—百度| 国产精品青草久久久久婷婷| 久久久久国产成人精品亚洲午夜| 欧美日韩精品久久久免费观看| 99久久er这里只有精品18| 久久露脸国产精品| 奇米综合四色77777久久| 久久久久人妻精品一区三寸蜜桃 | 欧美va久久久噜噜噜久久| 久久精品这里热有精品| 麻豆精品久久久久久久99蜜桃| 久久精品嫩草影院| 久久99久国产麻精品66| 国产精品欧美久久久久天天影视|