Alternative Classes with Different Interfaces

Prev don't be afraid of buying books Next

Alternative Classes with Different Interfaces

This Fowler and Beck [F] coding smell occurs when the interfaces of two classes are different and yet the classes are quite similar. If you can find the similarities between the two classes, you can often refactor the classes to make them share a common interface.

However, sometimes you can't directly change the interface of a class because you don't have control over the code. The typical example is when you're working with a third-party library. In that case, you can apply Unify Interfaces with Adapter (247) to produce a common interface for the two classes.


Refactoring to Patterns (The Addison-Wesley Signature Series)
Refactoring to Patterns
ISBN: 0321213351
EAN: 2147483647
Year: 2003
Pages: 103

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: