Implementing Class Adapter Pattern in Java

前端 未结 5 1085
失恋的感觉
失恋的感觉 2020-12-09 20:47

While reading up on the Class Adapter pattern in Head First Design Patterns, I came across this sentence:

class adapter... because you need multiple i

5条回答
  •  再見小時候
    2020-12-09 21:27

    The full story in heads up is: class adapter pattern is impossible in Java just because Java does not provide multiple inheritance.

    In their diagram, they show that the Adapter class subclasses both Target and Adaptee. Your example is (close to) the Object adapter pattern. The difference is that you implement the Target in your adapter class, rather then just subclassing the target (MyNeededInterface in your example)

提交回复
热议问题