• 结构型设计模式之外观模式(Facade)


    结构
    意图 为子系统中的一组接口提供一个一致的界面,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 进行通讯,从而简化了它们之间的依赖关系。
     1 using System;
     2 
     3     class SubSystem_class1 
     4     {
     5         public void OperationX() 
     6         {
     7             Console.WriteLine("SubSystem_class1.OperationX called");
     8         }
     9     }
    10 
    11     class SubSystem_class2
    12     {
    13         public void OperationY()
    14         {
    15             Console.WriteLine("SubSystem_class2.OperationY called");
    16         }
    17     }
    18 
    19     class SubSystem_class3 
    20     {
    21         public void OperationZ()
    22         {            
    23             Console.WriteLine("SubSystem_class3.OperationZ called");
    24         }    
    25     }
    26 
    27     class Facade 
    28     {
    29         private SubSystem_class1 c1 = new SubSystem_class1();
    30         private SubSystem_class2 c2 = new SubSystem_class2();
    31         private SubSystem_class3 c3 = new SubSystem_class3();
    32 
    33         public void OperationWrapper()
    34         {
    35             Console.WriteLine("The Facade OperationWrapper carries out complex decision-making");
    36             Console.WriteLine("which in turn results in calls to the subsystem classes");
    37             c1.OperationX();
    38             if (1==1 /*some really complex decision*/)
    39             {
    40                 c2.OperationY();
    41             }
    42             // lots of complex code here . . .
    43             c3.OperationZ();
    44         }
    45         
    46     }
    47 
    48     /// <summary>
    49     ///    Summary description for Client.
    50     /// </summary>
    51     public class Client
    52     {
    53           public static int Main(string[] args)
    54         {
    55             Facade facade = new Facade();
    56             Console.WriteLine("Client calls the Facade OperationWrapper");
    57             facade.OperationWrapper();      
    58             return 0;
    59         }
    60     }
    外观模式
  • 相关阅读:
    Operating System: Three Easy Pieces --- Page Replacement (Note)
    Operating System: Three Easy Pieces --- Page Fault (Note)
    Operating System: Three Easy Pieces --- Beyond Physical Memory: Mechanisms (Note)
    Operating System: Three Easy Pieces --- Paging: Small Tables (Note)
    Operating System: Three Easy Pieces --- Mechanism: Limited Direct Execution (Note)
    Operating System: Three Easy Pieces --- API (Note)
    Modern Operating System --- Chap 5.5.2 Clock Software
    Reed Solomon纠删码
    CodeBlocks 使用经验谈
    基于范德蒙矩阵的Erasure code技术详解
  • 原文地址:https://www.cnblogs.com/ziranquliu/p/4663318.html
Copyright © 2020-2023  润新知