Monday, 12 August 2013

Abstract Factory Design Pattern In ASP.Net With C# and VB.Net Example

Download AbstractFactoryDesignPatternExampleWithCSharp.zip C# Example.
Download AbstractFactoryDesignPatternExampleWithVB.Net.zip VB.Net Example.


Abstract factory pattern is expanded version of basic factory pattern. In Abstract factory pattern we unite similar type of factory pattern classes in to one unique interface.

Factory classes helps to centralize the creation of classes and types. Abstract factory help bring equability between related factory patterns classes. Which create more simplified interface for the client.

Now let's understand basic details of how to implement abstract factory patterns. We have the factory pattern classes which integrate to a common abstract factory classes through inheritance. Factory classes lay over concrete classes which are derived from common interface.
For instance in below figure we demonstrate "Implementation of abstract factory".

Abstract  Factory Design Pattern
(To view original image , click on image)


Both the concrete classes "ConcreateClass1" and "ConcreateClass2" inherits from one common interface. The client has to only interact with the abstract factory and the common interface from which the concrete classes inherit.


Now let's look at example.
We take scenario of display shapes from their centralized factory classes. Both these classes are inherit from common interface "InterfaceDisplayShpe", and both the factory classes "ClsFactorySquare" and "ClsFactoryCricle" inherits from the common factory "ClsAbstractFactoryShape".

From below figure you can see that client code only uses abstract factory class to object creation and call its method via interface.
Abstract  Factory Design Pattern
(To view original image , click on image)


Here is the code structure.

This images demonstrate that client uses abstract factory class and interface.

Abstract  Factory Design Pattern
(To view original image , click on image)


Below image demonstrate concrete class inherits from a common interface.

Abstract  Factory Design Pattern
(To view original image , click on image)

The most important points about the code is that it is completely isolated from the concrete classes. If any changes in concrete classes like adding and deleting concrete classes does not require client level changes.


To know deeply how method and interface call you need to download code and debug that.


Below are the books that you would like :


1 comment:

  1. Hi Jayesh,

    can u write an article on design patterns categories.

    1)CreationalPatterns. // i know only this.(for better object creation)

    i don't know. please explain with examples

    2)Structural Patterns.
    3)Behavioral Patterns.

    wait for your articles.

    ReplyDelete