Thursday, September 20, 2007

* Pattern : Abstract Factory Creational Pattern

Provides a single interface for creating families of related or dependent objects without using the concrete type name.

Consider the following class diagram :

In above diagram, CreateShapes acts as an single interface for creating various families of products. The diagram shows only Red shapes but it can be extended to create more color shapes.

The client code will look like this :

    public class Client
{
CreateShapes redShapes;

public void Run()
{
redShapes = new CreateRedShapes();
redShapes.CreateCircle();
redShapes.CreateSquare();
}
}

Once the current instance has been assigned to variable of type CreateShapes, the remaining code remains same for every family.


A practical use can be creating shapes for a particular theme.


The complete source code can be downloaded from following location : Abstract Factory Creational Pattern Source Code

1 comment:

  1. Hi Vikas,
    nice tutorials on the design patterns. will be good if you can try to use C# 3.0 and generics for the samples.

    ReplyDelete