Abstract Factory Pattern Code Review
Define the Client Object
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
The Client class is responsible for invoking the required methods against a particular product factory.
class Client
{
private IAbstractBag bag;
private IAbstractShoes shoes;
private IAbstractBelts belts;
public Client(IAbstractFactory factory) { bag = factory.CreateBag(); shoes = factory.CreateShoes(); belts = factory.CreateBelts(); }
public void ClientMain() { Console.WriteLine(String.Format("I bought a bag which is made from {0}.", bag.Material)); Console.WriteLine(String.Format("I bought some shoes which cost {0}.", shoes.Price.ToString())); Console.WriteLine(String.Format("I bought a belt made from {0} and cost {1}.", belts.Material, belts.Price.ToString())); } }
public Client(IAbstractFactory factory) { bag = factory.CreateBag(); shoes = factory.CreateShoes(); belts = factory.CreateBelts(); }
public void ClientMain() { Console.WriteLine(String.Format("I bought a bag which is made from {0}.", bag.Material)); Console.WriteLine(String.Format("I bought some shoes which cost {0}.", shoes.Price.ToString())); Console.WriteLine(String.Format("I bought a belt made from {0} and cost {1}.", belts.Material, belts.Price.ToString())); } }
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!