How and where Microsoft has implemented GOF design patterns in .Net Framework Part-I

Dhirendra
Posted by in Design Pattern & Practices category on for Advance level | Points: 250 | Views : 8884 red flag

In this series of articles, we will see how Microsoft has used GOF design patterns in .Net framework library. Let start with Absract factory Pattern....

Introduction Of abstract Factory Pattern

Abstract factory pattern is a software design pattern. It provides an abstract interface for creating instance of families of related object without providing actual implemented class name. So client can create/initiate concrate instance of the classes through the abstarct interface and client will only aware of the abstract interface which the abstract factory is returning. So this pattern helps if client is unaware of which object to construct at when and can work against the abstarct interface

Example code

See below code which returns the factory instance of SQLClientFactory and client just need to pass the name of the provider to initial to the GetFactory Method which returns  SQLClientFactory instance. In next statement, using factory instance's CreateCommand Method returns SQLCommand type as database specific command type.

using System.Data.SqlClient;

using System.Data;

using System.Data.Common;


static void Main(string[] args)

class Program

{

{

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");

DbCommand cmd = factory.CreateCommand();

Console.WriteLine("Provider Factory Instance Name :" + factory.GetType());

Console.WriteLine("Abstracted Command type name : " + cmd.GetType());

Console.Read();

}

}

Output of the program


.Net Framework Factory Implemented classes

if you search the factory/factories word in object browser window, then you will see there are lot of places where abstract factory pattern is used.




Hope this article was amazing !

Thanks for reading and let me know your feedback, comment.

Page copy protected against web site content infringement by Copyscape

About the Author

Dhirendra
Full Name: Dhirendra Patil
Member Level:
Member Status: Member
Member Since: 3/23/2010 2:39:20 PM
Country: India

http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)