Tag Archives: abstract

Abstract Factory Pattern Example With C#

Abstract factory pattern is to “provide an interface for creating families of related or dependent objects without specifying their concrete classes.”

For example a drawing & printing machine can process Low and High Resolution. Both have its own resolution drivers. Those drivers referred to concrete class with draw / print function. However the client implementation code asks the factory object class (not the concrete class) for a driver instance with provides information about resolution required. So this factory object return instance of concrete class.
The factory object implements an abstract class. It can instantiates a concrete class and return to client with casted to factory’s parent which is abstract Resolution driver.
The client uses the resolution driver as abstract without being aware about their concrete implementation.

Benefit of using factory pattern is in client code implementation, new resolution can be added with just providing that new resolution info as argument. So no change in client code.
Continue reading