zoukankan      html  css  js  c++  java
  • Head First Design Patterns Facade Pattern

    The Facade Pattern provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

    A facade not only simplifies an interface, it decouples a client from a subsystem of components.

    Facades and adapters may wrap multiple classes, but a facade's intent is to simplify, while an 

    adapter's is to convert the interface to something different.

    The principle of least knowledge - talk only to your immediate friends.

    the principle tell us that we should only invoke methods that belong to:

    • The object itself
    • Objects passed in as a parameter to the method.
    • Any objects the method creates or instantiates
    • Any components of the object

    Summarize:

    • when you need to use an existing class and its interface is not the one you need, use an adapter
    • when you need to simplify and unify a large interface or complex set of interfaces, use a facade.
    • An adapter changes an interface into one a client expects.
    • A facade decouples a client from a complex subsytem.
    • Implementing an adapter may require little work or a great deal of work depending on the size and complexity  of  the     target  interface.
    • Implementing a facade requires that we compose the facade with its subsystem and usedelegation to perform the work   of the facade.
  • 相关阅读:
    Java 泛型 泛型的约束与局限性
    Java 泛型 泛型方法
    Java 泛型 泛型数组
    Java 泛型 协变性、逆变性
    Java 泛型 协变式覆盖和泛型重载
    Java 泛型 泛型代码和虚拟机
    Insertion Sort List
    Remove Duplicates from Sorted List II
    String to Integer (atoi)
    SpringMvc源码入门
  • 原文地址:https://www.cnblogs.com/zhuqiang/p/2468323.html
Copyright © 2011-2022 走看看