Album Cover

Design Patterns Essentials Java

Close Preview
This exercise is all about cleaning up the code smell, Alternative Classes with Different Interfaces
Alternative Classes With Different Interfaces Example
The XMLBuilder features logic to construct a tree structure using instances of TagNode.
The DOMBuilder contains the exact same tree-construction logic, only it uses instances of classes that implement the Element interface (from the Document Object Model).
There is a great deal of duplicated tree-construction code in each of the builders because TagNode and Element don't share a common interface.
Understood. If TagNode and Element shared a common interface, the builder logic would become identical, thereby allowing it to be shared in a builder superclass. Sounds like a job for the Adapter pattern.
| Tweet...
Page rating: | Rate this Page