I think I need an adapter pattern here, but I seem to be repeating method implementation details
You can see below that I have two concrete classes that ca开发者_高级运维n share almost all of the implementation details already provided through an abstract class. They each only have to implement 2-3 methods themselves. However, ImplOne also implements from InterfaceTwo, which has an additional 1-2 methods to implement. I don't want to have to provide the exact same implementation details in ImplOne as I do in AbstractImpl, but what I have here currently does not seem right. In the adapter pattern, from the examples I've seen, the implementation details do seem to be duplicated for the interfaces being adapted.
InterfaceOne
/ \
InterfaceTwo AbstractImpl
\ / \
ImplOne ImplTwo
It is no problem with this scenario. ImplOne must implement all methods declared in interfaceOne or interfaceTwo unless already implemented by abstractImpl. implOne must also implement abstract methods from abstractImpl. As an exercise, I suggest creating an ImplOne with no methods and let the compiler tell you what methods need implementing.
精彩评论