Factory design pattern
Factory design pattern is creational design pattern, and came into play when their was requirement of fixing 2 major issues:
- Avoiding using new keyword again and again in code.
- Avoid client to know internal class hierarchy, means client side implementation should not include internal knowledge of business layer.
In the example we have divided application into 4 projects:
1. Interface project
2. Class project where classes are implementing interface
3. Static class project in which static method is returning reference of interface created in first project
4. Windows application project (End Client)
Below is solution diagram.
Factory design pattern first help you to remove client application direct link to operational classes. Instead intermediate class is used to provide reference of interface pointing to requested class. With this first client is not supposed to remember different classes and condition required to call them. Also using of new keyword is avoided.