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

            搜索

            •  

            積分與排名

            • 積分 - 1804752
            • 排名 - 5

            最新評論

            閱讀排行榜

            99久久精品国产高清一区二区| 中文字幕无码久久人妻| 亚洲成人精品久久| 久久久精品日本一区二区三区 | 93精91精品国产综合久久香蕉 | 91久久精品视频| 无夜精品久久久久久| 久久久久久伊人高潮影院| 狠狠色婷婷久久一区二区三区 | 亚洲欧美精品伊人久久| 狠狠久久综合伊人不卡| 久久亚洲国产精品成人AV秋霞| 久久精品国产亚洲AV高清热| 久久97精品久久久久久久不卡| 久久国产免费直播| 色欲综合久久躁天天躁蜜桃| 青青青伊人色综合久久| 色诱久久av| 91精品国产高清91久久久久久| 久久伊人中文无码| 99久久婷婷国产综合亚洲| 精品免费久久久久国产一区| 狠狠综合久久综合88亚洲| 色综合久久久久| 亚洲国产精品无码久久SM | 国内精品伊人久久久久| 久久夜色撩人精品国产| 99久久er这里只有精品18| 中文字幕久久亚洲一区| 一本大道加勒比久久综合| 亚洲精品蜜桃久久久久久| 久久青青草原亚洲av无码| 久久精品亚洲日本波多野结衣| 人妻精品久久久久中文字幕| 久久精品免费观看| 久久99国产乱子伦精品免费| 亚洲国产小视频精品久久久三级| 久久精品www| 99久久99久久久精品齐齐| 午夜精品久久久久久久| 中文字幕精品久久|