Monday, March 17, 2014

Factory Pattern (FP)

FP identified as a creational pattern. (Provides one of the best way to create an object)

FP specifies about creating objects without exposing the creation logic to the client.
And also it refer to newly created objects using a common interface.

Implementation of FP >
1. Create a interface class called "Shape"
2. Create a set of concrete classes inpleing the "Shape" interface

3. Define the factory class class as "ShapeFactory"

4.Creates the "FactoryPatternDemo" Class which holds the Main().
    •  It will use the "ShapeFactory" class to get a "Shape" objects, without instantiating the objects of shapes directly on main(). ]
    • The Main() will pass the relevant shape to the class "ShapeFactory", which will return an object of the requested shape.















No comments:

Post a Comment