Factory Design Pattern

Factory Pattern is a design pattern to create objects based on the type with the help of Factory class.

Factory Class create and return the object based on the type of request, and Caller class not aware of which class returned, however the created class do the operation based on the requested type.

In this example, we have MathFactory Class, where this class return objects of MathOperation which do the operation of addition, subtraction, multiply and division based on the user request during the object created.

All Factory created objects use a common methods to do the functionality, but it will do the operation of its own based on the request type used while creation.

Result:

You may also like...

Leave a Reply

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