Factory Method Pattern Code Review
Use the Factory Method Pattern
Code Review
- Factory Method Pattern Code Review: Define the Factory Object
- Factory Method Pattern Code Review: Define the Product Interface and Handler Objects
- Factory Method Pattern Code Review: Use the Factory Method Pattern
Code Walkthrough
The Program class creates an instance of the Factory class, and creates instance of IProduct interface.
class Program
{
static void Main(string[] args)
{
Factory factory = new Factory();
Product.IProduct product;
for (Int32 i = 1; i <= 12; i++) { product = factory.FactoryMethod(i); Console.WriteLine(String.Format("Product {0}", product.ShipFrom())); }
Console.Read(); } }
for (Int32 i = 1; i <= 12; i++) { product = factory.FactoryMethod(i); Console.WriteLine(String.Format("Product {0}", product.ShipFrom())); }
Console.Read(); } }
During the iteration process a specific Product subclass is created by the FactoryMethod() method and relevant ShipFrom() method invoked on the subclass.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!