10

(This question was closed on Stack Overflow due to being "too broad" and "not a real question" so maybe it's more appropriate here?)

Inspired by this question. We know events are a language-level implementation of the Observer pattern. Are there other design patterns implemented as language features in C#? I want to keep this question C#-specific because there are lots of design patterns implemented in other languages, and I want to keep this focused.

I'm not looking for pattern implementations in the BCL (such as decorator in many WCF classes or Factory Method in WebClient), but language-level patterns.

So far I'm aware of observer (event) and iterator (foreach in combination with many BCL classes and interfaces). There are probably other obvious ones I'm missing.

asked Mar 25, 2011 at 2:55

2 Answers 2

1

Delegates are de facto strategy patterns

answered Mar 25, 2011 at 3:59
2
  • funny, just yesterday a collegue was saying delegates are an implementation of the command pattern. Depends on how you look at it I guess (afaik command should encapsulate the arguments as well, but in case of a method without arguments..) Commented Mar 25, 2011 at 8:20
  • 1
    I wouldn't say delegates are implementation of command patterns, atleast I can't see how you could implements things like undo/redo using only delegates. They might be part of a command object but that's another matter Commented Mar 25, 2011 at 8:41
0

Extension methods are an abstraction of the Decorator pattern.

answered Mar 25, 2011 at 9:03
2
  • Not really. Decorator allows us to composed objects at run-time to add data and behaviour. Commented Mar 25, 2011 at 19:28
  • 1
    True - so they're not nearly as useful as real decorator patterns. Would it be better to say that much of the problems solved by extension methods are solved with decorator patterns in other languages? Commented Mar 28, 2011 at 10:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.