A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Most of the design patterns encourage loose coupling. loose coupling make sense when we are in a situation to modify some piece of code in a large application.
If the code is tightly coupled modifying one code will trigger a chain of modifications to many other parts. In that case modifications to the existing code will become hectic and troublesome.
Factory Pattern
As I said earlier, the problem is tight coupling. Functions and classes in one part of the system rely too heavily on behaviors and structures in other functions and classes in other parts of the system.
You need a set of patterns that lets these classes talk with each other, but you don’t want to tie them together so heavily that they become interlocked.
Factory patterns can be used to implements loose coupling for object creation. Factory pattern can be considered as a class which can create the object for you. So the actual implementation of object initialization will be hidden from you.
Continue reading
