Factory Pattern

-> In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.
-> Separate object creation from the decision of which object to create.
-> Defer creation of objects. Only create them if and when needed.
-> Creating instance of several of derived classes. Factory method decides which derived concrete object to be created.

Step 1
-> Create an interface

Step 2-> Create concrete classes implementing the same interface.



Step 3
Create a Factory to generate object of concrete class based on given information.



Leave a Reply

Your email address will not be published. Required fields are marked *