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 閱讀(228) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 晋宁县| 云阳县| 平潭县| 奇台县| 华宁县| 无极县| 丽水市| 和平县| 库尔勒市| 同江市| 沭阳县| 翁源县| 开阳县| 云梦县| 获嘉县| 常宁市| 长泰县| 清苑县| 藁城市| 潼关县| 百色市| 卢湾区| 民乐县| 九龙坡区| 治县。| 原平市| 钦州市| 北京市| 宣恩县| 曲麻莱县| 郧西县| 开阳县| 太保市| 富裕县| 庆云县| 茂名市| 麻城市| 师宗县| 大竹县| 道孚县| 北京市|