Java: Factory design pattern example
The factory method is a creational design pattern, i.e., related to object creation. In Factory pattern, we create an object without exposing the creation logic to the client and the client uses the same common interface to create a new type of object. The idea is to use a static member-function (static factory method) that creates & returns instances, hiding the details of class modules from the user. A factory pattern is one of the core design principles to create an object, allowing clients to create objects of a library in a way such that it doesn’t have tight coupling with the class hierarchy of the library. Factory Design Pattern Advantages The Factory design pattern provides an approach to code for interface rather than implementation. Factory pattern removes the instantiation of actual implementation classes from client code. The factory pattern makes our code more robust, less coupled, and easy to extend. Factory pattern provides abstraction between implemen