Sunday, October 16, 2011

Design Patterns which are used in .NET Framework base class library

As we know that .net is an OOPs based language so we can easily implement design patterns in our projects but some times it comes to mind that, which all design patters microsoft .NET Base Class Library is using internally.
NOTE: This question also popular in interviews.
Lets walk through few Design patterns used in .NET BCL:

Observer Pattern:
This observer design pattern is used for delegates and events.

Iterator Pattern:
Iterator design pattern used in foreach in C# and For Each in Visual Basic .NET

Decorator Pattern:
System.IO.Stream :Any useful executable program involves either reading input, writing output, or both. Regardless of the source of the data being read or written, it can be treated abstractly as a sequence of bytes. .NET uses the System.IO.Stream class to represent this abstraction.

CryptoStream :System.Security.Cryptography.CryptoStream to encrypt and decrypt Streams on the fly, without the rest of the application needing to know anything more than the fact that it is a Stream.

Adapter Pattern:
By allowing managed classes and COM components to interact despite their interface differences, RCWs are an example of the Adapter pattern. The Adapter pattern lets you adapt one interface to another. COM doesn't understand the System.String class, so the RCW adapts it to something that it can understand. Even though you can't change how a legacy component works, you can still interact with it. Adapters are frequently used like this.

Factory Pattern:
System.Convert: System.Convert class contains a host of static methods that work like factory design pattern.

System.Net.WebRequest:
This class is used to request and receive a response from a resource on the Internet.FTP, HTTP, and file system requests are supported by default. To create a request, call the Create method and pass in a URI. The Create method itself determines the appropriate protocol for the request and returns the appropriate subclass of WebRequest: HttpWebRequest, FtpWebRequest, or FileWebRequest. The caller doesn't need to know the specifics of each protocol, only how to invoke the factory and work with the WebRequest that gets returned. If the URI changes from an HTTP address to an FTP address, the code won't have to change at all.

Strategy Pattern:
Both Array and ArrayList provide the capability to sort the objects contained in the collection via the Sort method. Strategy Design Pattern is used with Array and Arraylist to sort them using different strategy without changing any client code using IComparable interface

Composite Pattern in ASP.NET:
ASP.NET has lots of controls. A control may be a simple single item like a Literal, or it could be composed of a complex collection of child controls, like a DataGrid is. Regardless, calling the Render method on either of these controls should still perform the same intuitive function.

Because the domain of controls is so diverse, there are several intermediate derived classes like WebControl and BaseDataList that serve as base classes for other controls. Though these classes expose additional properties and methods, they still retain the child management functions and core operations inherited from Control. In fact, the use of the Composite pattern helps to hide their complexity, if desired. Regardless of whether a control is a Literal or a DataGrid, the use of Composite means you can just call Render and everything will sort itself out.

Template Method Pattern:
custom controls are example of Template Method Pattern.


Reference: http://msdn.microsoft.com/en-us/magazine/cc188707.aspx

Compiled By: Rajesh Rolen

Share This!


32 comments:

Bhupendra Singh said...

It's Really nice sir

Unknown said...

Amazing post with useful tips, thanks for sharing.
Regards,
DOT NET Training in Chennai

Unknown said...

Given so much information in it. its very useful .perfect explanation about Dot net .Thanks for your valuable information. dot net training in chennai velachery |
dot net training in velachery

Unknown said...

Given so much information in it. its very useful .perfect explanation about Dot net .Thanks for your valuable information.

Unknown said...

Hi Admin,
Excellent blog and it’s totally loaded with valid posts on Java and .Net technology. Consider including RSS feed in your blog, so aspirants like me can follow your blog easily.
DOT NET Training in ChennaiDOT NET Course in Chennai

rmouniak said...


This blog is very useful for me and thanks for sharing
.Net Online Training

rmouniak said...


Learned a lot of new things from your post!Good creation ,It's amazing blog
.Net Online Training
Dot Net Online Training Bangalore
.Net Online Course

rmouniak said...

Net Nice post! I really enjoy this blog
Dot Net Online Training

Mounika said...

I’ve desired to post about something similar to this on one of my blogs and this has given me an idea. Cool Mat.
Click here:
Microsoft azure training in sollinganallur
Click here:
Microsoft azure training in btm

sai said...

I appreciate that you produced this wonderful article to help us get more knowledge about this topic. I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!
Click here:
angularjs training in sholinganallur
Click here:
angularjs training in btm
Click here:
angularjs training in rajajinagar

Unknown said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium Training in Chennai

Unknown said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium Training in Chennai

Unknown said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium Training in Chennai

pooja said...

Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 

Blueprism training in annanagar

Blueprism training in velachery

Blueprism training in marathahalli


AWS Training in chennai

AWS Training in bangalore

gowsalya said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Devops training in tambaram|Devops training in velachery|Devops training in annanagar|Devops training in sholinganallur

janani said...

It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
java training in annanagar | java training in chennai

java training in chennai | java training in electronic city

Unknown said...

Resources like the one you mentioned here will be very useful to me ! I will post a link to this page on my blog. I am sure my visitors will find that very useful
Data Science course in Chennai | Data science course in bangalore
Data science course in pune | Data science online course
Data Science Interview questions and answers | Python course in Kalyan nagar

Anonymous said...

I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!

angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

angularjs Training in bangalore

gowthunan said...

Hey there! I know this is kind of off-topic, but I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa? My blog goes over a lot of the same topics as yours
industrial safetyu courses in chennai

DeepikaOrange said...


It’s great to come across a blog every once in a while, that isn’t the same out of date rehashed material. Fantastic read.
Cloud Training
Software Testing Training
Oracle DBA Training
Angular Training in Chennai

gowthunan said...

Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and I will surely implement them in my study. Keep blogging article like this.
industrial course in chennai

gowthunan said...

The great service in this blog and the nice technology is visible in this blog. I am really very happy for the nice approach is visible in this blog and thank you very much for using the nice technology in this blog
industrial course in chennai

gowthunan said...

It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
iosh safety course in chennai

gowthunan said...

Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.
iosh safety course in chennai

sasireka said...

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…

informatica mdm online training

apache spark online training

apache spark online training

devops online training

aws online training

rose said...

Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
Microsoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training

Shanthi Cabs said...

Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels

Janu said...

Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way. T hank you so much.



Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery



Banumadhu said...

Useful article which was very helpful. also interesting and contains good information.
to know about python training course , use the below link.

Python Training in chennai

Python Course in chennai

Banumadhu said...

Useful article which was very helpful. also interesting and contains good information.
to know about python training course , use the below link.

Python Training in chennai

Python Course in chennai

rajmohan1140 said...

Best of luck for your next blog.
Thank you for such a wonderful article and sharing. God bless you.

Java Training in Chennai

Java Course in Chennai

rajmohan1140 said...

Best of luck for your next blog.
Thank you for such a wonderful article and sharing.God bless you.!


Java Training in Chennai

Java Course in Chennai

Powered By Blogger · Designed By Seo Blogger Templates