Problem | Solution | Patterns |
Your code depends on the names of classes. Changing the class of an object is burdensome because the name of the class is hard-coded in the client program through constructor invocations. | Do not use constructors directly in your client classes. Provide an extra level of indirection to the code that invokes the constructor. |
Abstract Factory Factory Method Prototype |
Your code depends on platform idiosyncrasies. #ifdef and conditional compilation only takes you so far. Even Java's vaunted platform independence has a few weak spots. |
Isolate the platform-dependent parts of your program from the platform-independent parts. | Abstract Factory Bridge |
Your code depends on specific methods in specific classes. | Separate the request itself from the object and/or method that handles the request. | Chain of Responsibility Command |
Your code depends too closely on exactly how an object is implemented. Changing the implementation of the class forces change on the client class. Encapsulation isn't airtight. | This is more often a problem in C++ with its pointers, pointer arithmetic, and relatively close access to the machine than it is in Java. Often the solution is to wrap an additional layer of interface around the implementation. |
Abstract Factory Bridge Memento Proxy |
Changing an algorithm requires too many changes in the classes that use it, especially changes that affect the class's interface as well as its implementation. | The algorithm should be separated from the class, and moved into a class of its own. |
Builder Iterator Strategy Template Method Visitor |
Classes are excessively dependent on each other. It's difficult to change one class without changing most or all other classes. | Separate classes with additional levels of indirection. |
Bridge Chain of Responsibility Mediator Observer Command Façade |
Subclassing is too difficult. | Use object composition and delegation instead. |
Bridge Chain of Responsibility Observer Decorator Composite, Strategy |
A class can't be modified, either because you don't have its source code or because too many other classes depend on it. | Use object composition to embed an instance of the class inside another class that provides a new interface. Delegate requests to the embedded object. |
Adaptor Decorator Visitor |