The Factory Design Pattern is probably the most used design pattern in modern programming languages like Java. Here we discuss about it and I will show you a demo.

A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. It means Subclasses are responsible to create the instance of class.
This Pattern also known as Virtual Constructor.
What is the Intention?
Factory Method makes a design more customizable and only a little more complicated. Other design patterns require new classes, whereas Factory Method only requires a new operation.
People often use Factory Method as the standard way to create objects; but it isn't necessary if the class that's instantiated never changes, or instantiation takes place in an operation that subclasses can easily override.
Factory Method is similar to Abstract Factory but without the emphasis on families.
Factory Methods are routinely specified by an architectural framework, and then implemented by the user of the framework.
Example:
First of all we create an abstract class and then we make some concrete classes which extends the abstract class.
Then we create an another class to get the object of abstract class.
Finally we will create main class in which do the work for us.(The business Logic Part I guess !!)
Here is the link of Example. Factory Pattern in Java
Output :
Subscribe for more updates on Java.

A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. It means Subclasses are responsible to create the instance of class.
This Pattern also known as Virtual Constructor.
What is the Intention?
- Define an interface or abstract class for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
- Creates objects without exposing the instantiation logic to the client.
- It promotes the loose-coupling by eliminating the need to bind application-specific classes into the code.
Factory Method makes a design more customizable and only a little more complicated. Other design patterns require new classes, whereas Factory Method only requires a new operation.
People often use Factory Method as the standard way to create objects; but it isn't necessary if the class that's instantiated never changes, or instantiation takes place in an operation that subclasses can easily override.
Factory Method is similar to Abstract Factory but without the emphasis on families.
Factory Methods are routinely specified by an architectural framework, and then implemented by the user of the framework.
Example:
First of all we create an abstract class and then we make some concrete classes which extends the abstract class.
Then we create an another class to get the object of abstract class.
Finally we will create main class in which do the work for us.(The business Logic Part I guess !!)
Here is the link of Example. Factory Pattern in Java
Output :
Subscribe for more updates on Java.



