Abstract Factory Design Pattern

Abstract Factory Design Pattern
Creational pattern
Among the creational pattern, we will discuss how the Abstract Factory is useful in detail.
Abstract Factory
This is mostly useful when we are dealing where the application needs to be ported in different operating system. Create an abstract interface which it deals with the methods to be instantiated for the different operating system.
What could be the problem if you are not using the Abstract factory design pattern?
1. Code will not look good and maintenance is difficult
2. Porting to different operating system is a time consuming work
3. Abstraction will not be followed as we expected
What are the advantages of implementing the Abstract factory design pattern?
1. Code is easier to maintain
2. Porting to different operating system is easy and it could be extended. This means a new class needs to be instantiated and this will take care of handling the mechanism for new operating system
How to implement the Abstract factory design pattern?
Create base class with pure virtual function and inherit the child class based on the porting as required. Number of child classes to be inherited is based on the number of operating system to be ported. In the man() function as based on the operating system by using "#ifdef" the instantiation of the child class to the base class can be done.

No comments: