Factory Pattern Applicability & Examples
by, 03-09-2012 at 08:09 PM (676 Views)
Factory pattern is most widely used pattern.
E.g, graphical applications do their work along with shapes. In implementations, shapes are products and drawing frameworks are the clients. An abstract shape is responsible for the derivation of the shapes. Shape class defines the move operations and draw that shall be implemented by concrete shapes. Now let us assume that a particular command has been selected from menu so that to make a new circle. Shape type is being received by the framework as a string parameter so it asks factory to make newer shapes, sending the parameters that are received by the menu. New circle is created by the factory and is returned back to the framework. Then, object that has been casted the abstract class would be used by the framework, without knowing the type of the concrete object.
Its advantage is that new shaped could get added without making any kind of change even a single line of code present in the framework. It has been given in next section that certain factory implementations are present which permit the addition of the new products without doing the modification of the factory class.