Abstract Factory Pattern Code Review
Define the Pattern Interface and Handler Objects
Code Download
- Download Description:abstract factory pattern download
- .NET Framework:3.5
- .NET Language:C#
- Date Published:2009-07-01
- Download Size:9 KB
Code Review
- Abstract Factory Pattern Code Review: Define the Pattern Interface and Handler Objects
- Abstract Factory Pattern Code Review: Define the Product Interfaces and Handler Objects
- Abstract Factory Pattern Code Review: Define the Client Object
- Abstract Factory Pattern Code Review: Use the Abstract Factory Pattern
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();
}
}