weidagang2046的專欄

          物格而后知致
          隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
          數據加載中……

          Adapter Design Pattern

          Note:  Do not confuse the abstract concept of an "interface" with the Java "interface" type in the following discussion!  

          Adapters are used to enable objects with different interfaces to communicate with each other.

          Adapters come in two flavors, object adapters and class adapters.  These two methods embody the difference between the use of inheritance and composition to solve problems.

          Object Adapters

          Object adapters use a compositional technique to adapt one interface to another.    The adapter inherits the target interface that the client expects to see, while it holds an instance the adaptee.   When the client calls the request() method on its target object (the adapter), the request is translated into the corresponding specific request on the adaptee.

          Object adapters enable the client and the adaptee to be completely decoupled from eachother.   Only the adapter knows about both of them.

          Class Adapters

          Class adapters use multiple inheritance to achieve their goals.   As in the object adapter, the class adapter inherits the interface of the client's target.   However, it also inherits the interface of the adaptee as well.   Since Java does not support true multiple inheritance, this means that one of the interfaces must be inherited from a Java Interface type.   Note that either or both of the target or adaptee interfaces could be an Java Interfaces.   The request to the target is simply rerouted to the specific request that was inherited fro the adaptee interface.

          Note that class adapters have a problem with name conflicts if methods of the same signature exist on both the target and the adaptee.  Note that just because two objects have methods that have the same signature (syntax), it does not guarantee that the two methods have the same meaning or behavior (sematics).    That is, the two methods do not necessarily map directly to each other.   Object adapters do not have this problem.

          Class adapters are simpler than object adapters in that they involve fewer classes and are useful if total decoupling of the client and adaptee is not needed.

          from: http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/adapter.htm

          posted on 2006-02-26 22:46 weidagang2046 閱讀(226) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 西峡县| 平果县| 宜兴市| 阳西县| 二手房| 富顺县| 博湖县| 临邑县| 盘锦市| 丹寨县| 东山县| 永安市| 婺源县| 宁海县| 建平县| 长子县| 宝山区| 苗栗市| 大方县| 江陵县| 诸暨市| 乳源| 崇阳县| 霍州市| 乌兰县| 建阳市| 尉犁县| 虞城县| 民乐县| 进贤县| 龙陵县| 奈曼旗| 宜城市| 和静县| 新巴尔虎右旗| 中西区| 方正县| 望江县| 淮南市| 周宁县| 屏南县|