I am having trouble reconciling a walk through example in intro to design patterns chapter. I copied several images of the chapter's assertion, solution, and apparent contradictions.
Problem: Joe was berated for having rubber ducks flying around on his simulator. He eventually proposes "How about an interface?" There, the MallordDuck (and others) are declared as children of the Duck class and implement one or more interfaces.
For which he is again berated by the lady supervisor who asks "how are going to feel when you have to make a change to the flying behavior in all 48 duck classes?" The text to the right of the supervisor asserts that it completely destroys code reuse for those behaviors
And in the programming to an interface solution the UML illustration appears to require same amount of duplicate code that Joe was berated for. It doesn't seem to solve that problem. The only way I can think of to do so is to put the most used implementation for fly() and Quack() into the interface (which isn't possible in Java - I guess) and may be something you don't want to do even if were possible. In addition it seems that they are also hidden behind the interface...
Well I've either overthought this too much or I just don't understand the assertions of code duplicatation and "these behaviors are no longer hidden away in our Duck classes"
Any clarification or further explanations are greatly appreciated.
thank you Kial



Aucun commentaire:
Enregistrer un commentaire