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.
  • 相关阅读:
    Cocos2d-x之绘制圆形
    Cocos2d-x之绘制填充矩形
    Cocos2d-x之绘制矩形
    Cocos2d-x之绘图API说明
    cocos2d-x之监听手机的物理按键
    cocos2d-x之加速度传感器
    cocos2d-x之多点触摸事件
    cocos2d-x之事件传递(onTouchBegan的返回值的作用)
    pickle
    配置文件
  • 原文地址:https://www.cnblogs.com/zhuqiang/p/2468323.html
Copyright © 2011-2022 走看看