Abstract Factory Pattern Code Review

Define the Pattern Interface and Handler Objects

Code Download

Code Review

Code Walkthrough

Define the IAbstractFactory interface to be used as the "blueprint" for the factory application classes.

interface IAbstractFactory { IAbstractBag CreateBag(); IAbstractShoes CreateShoes(); IAbstractBelts CreateBelts(); }

This interface is used to instantiate the different product classes (objects).

The FactoryGucci class (object) represents a factory class that instantiates a particular set of product classes. These product classes are related to each other.

class FactoryGucci : IAbstractFactory { public IAbstractBag CreateBag() { return new GucciBag(); } public IAbstractShoes CreateShoes() { return new GucciShoes(); } public IAbstractBelts CreateBelts() { return new GucciBelts(); } }

The FactoryPoochy class (object) represents a factory class that instantiates a different set of product classes. These product classes are related to each other.

class FactoryPoochy : IAbstractFactory { public IAbstractBag CreateBag() { return new PoochyBag(); } public IAbstractShoes CreateShoes() { return new PoochyShoes(); } public IAbstractBelts CreateBelts() { return new PoochyBelts(); } }