Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Incorporating changes that were not anticipated in the original software design can sometimes require changes to existing code. Modifying existing code that works well should be avoided if at all possible as it can result in unintended consequences such as the introduction of new bugs. A slight change in a dependant module can result in breaking a program in several places if there's tight coupling between code segments.
Code that handles change well is possible using good OO design. The factory method pattern is an excellent solution to this recurring requirement. The factory method pattern is a solution to one of the most common reasons for tight coupling, which is caused by one class instantiating another class and using the resultant object. Of course, classes need to be instantiated – there's no way to write code that does not instantiate classes. So, what are we talking about?