Adapter

作者: 相关知情人士 | 来源:发表于2017-05-16 15:31 被阅读0次

    UML :

    adapter.png

    introduction :

    /**
     * An adapter helps two incompatible interfaces to work together. This is the real world definition
     * for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
     * The Adapter design pattern allows otherwise incompatible classes to work together by converting
     * the interface of one class into an interface expected by the clients.
     *
     * There are two variations of the Adapter pattern: The class adapter implements the adaptee's
     * interface whereas the object adapter uses composition to contain the adaptee in the adapter
     * object. This example uses the object adapter approach.
     *
     * The Adapter ({@link BattleFishingBoat}) converts the interface of the adaptee class (
     * {@link FishingBoat}) into a suitable one expected by the client ( {@link BattleShip} ).
     *
     * The story of this implementation is this. <br>
     * Pirates are coming! we need a {@link BattleShip} to fight! We have a {@link FishingBoat} and our
     * captain. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
     * captain needs a battleship which can fire and move. The spec is in {@link BattleShip}. We will
     * use the Adapter pattern to reuse {@link FishingBoat}.
     *
     */
    
    • 结构型设计模式
      • 主要细节在于 : 适配器会持有一个因需求而被代理的对象,然后 代理 具体的细节,返回成需求的需要的细节,就使得被代理对象仍得以使用

    相关文章

      网友评论

          本文标题:Adapter

          本文链接:https://www.haomeiwen.com/subject/nselxxtx.html