views:

230

answers:

5

Can you share your most frequently applied (or favorite) software design patterns in .NET development? And why?

Please bear with me by asking such a generic question. I am not trying solve any problem specifically. Simply want to know what patterns are used more frequently to help solving problems we face daily.

Thanks for sharing your two cents.

A: 

What design pattern do you use the most? : All of them can be applied in the world of .NET.

Moayad Mardini
+1  A: 
  • Composite pattern

Each object have 1 parent and may have n children.

  • Controler pattern

On one side you have classe (DataClass) that represents the data, and on the other 1 classe that contains a list of DataClass (ControlerClass). Only this ControlerClass instanciate/modify/delete any object of DataClass.

  • Singleton Pattern

Allo a class to instanciate only 1 object, by designing the constructors as private, and design a static getter that return either a new object, or the existing object

Many of pattern are used, but these one are really common.

Clement Herreman
Hmm, I was advised to keep away from the Singleton pattern where possible, because it just looks like 1 giant global variable... Which it is when you think about it. Obviously there are some instances where this is desired, but need to be careful.
Ian
There's only one correct implementation for singletons: configuring the class' lifecycle as singleton in the container :)
Thomas Freudenberg
+11  A: 

There's a saying I once heard:

"The trouble with getting a new hammer is, everything starts to look like a nail"

This question appears to be asking for solutions, with little concern to what the problems actually are. Far too frequently people adopt favourite patterns, and apply them religously whether or not they are the best tool for the job.

If you want to start on design patterns though, I'd suggest by reading one of the many books on the subject such as the classic Gang Of Four book "Design Patterns" by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, ISBN-13 978-0201633610 or for a more C# flavour, try "C# 3.0 Design Patterns" by Judith Bishop, ISBN-13 978-0596527730.

MPritch
Tip: When referencing published books, it is better to add links to the books (such as pages on Amazon or the publishers site) rather than adding an ISBN number. Most posters prefer to edit their answer with that information because it can be time consuming to find the links. +1
Cerebrus
I considered doing that (all the information I entered was from Amazon anyway), but decided against on the basis that it's just advertising for Amazon and also it limits it to a single country. I felt the ISBN-13 number allowed the books to be immediately identified, without any of these ties. I am reconsidering this though, given their size - I suppose it's like saying 'no, I don't use google' :-)
MPritch
OK, caved in and added links. Guess I'm now a sell out :-)
MPritch
+1 to the answer here. It frustrates me to no end when I see inexperienced developers looking to conform without asking why. Research the problem, then find a solution. If there is a pattern that fits the mold, you'll more than likely come across it during your research. Then, if you have specific questions about a pattern, ask them. Blanket questions like this really don't serve a useful purpose.
Chris
Absolutely spot on.
David M
Considering the question, I would have said Head First: Design Patterns, but +1 for the right answer
Matt Briggs
+2  A: 

Well if you include the built in ones, it'd have to be Iterator (Enumeration) and Observer (Events) :)

Ian
A: 

Besides the obvious Iterator and Observer, I would say:

  • Strategy
Alex Baranosky