Abstract Factory Pattern
In java abstract factory pattern is a design pattern which provides the technique to encapsulate group of individual factories where common theme are available.
In regular usage, it is where client creates concrete implementation of abstract factory pattern and then uses generic interfaces to create related concrete objects that are part of theme. Client does not need to know where concrete objects it gets from each of these internal factories, because it uses only generic interfaces of their related products. Abstract factory pattern separates details of its implementation of set of objects from their general usage.
Abstract Factory Pattern Example:
- Create an abstract factory pattern interface which will have one method to return factory of software company
- Abstract Factory Pattern: Create class and implement SoftwareCompanyFactory interface
- Create factory interface which will have one method to return factory of software company product
- Create class and implement SoftwareCompany interface
- Create client interaction class to get object at runtime based on demand
- Now create client and use abstract factory:
- That’s it. Below is list of all design patterns link:
- Chain of Responsibility
- Template Method