This is somewhat related to Does functional programming replace GoF design patterns?
Since the introduction of lambdas and dynamics in C#, are there any of the standard design patterns that could be considered obsolete or solved in some other way using lambdas or other language features?
For example, the dynamic features of C# can now be used to do multi methods. http://achoiusa.wordpress.com/2009/08/27/exploring-c-4-0-multimethods/ (I think Marc Gravell had some post about this to ?)
Personally I tend to do factories using Func of T nowdays.
e.g.
public static class SomeFactory
{
public static Func<IUnitOfWork> GetUoW =
() => new EF4UoW(new SomeModelContainer());
}
// usage
var uow = SomeFactory.GetUoW();
// testabillity
var testUoW = new InMemUoW();
testUoW.Add(new Customer()...);
SomeFactory.GetUoW = () => testUoW;
// the service can get an UoW using the factory
var result = SomeDomainService.DoStuff(...);
Anyone got other examples?
[Edit] Ofcourse the patterns don't go obsolete per se but some patterns are paradigm specific and thus since C# is now multi paradigm, some of the functional properties of C# may make some of the OOP patterns less attractive.
Yes, but that changed from a pattern which is a design idea that you read about in a book and apply to your code, to "just code".
Here's the blurb: In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID. The functional programming community has design patterns and principles as well.
Design patterns do not become obsolete just because a single language evolves. Patterns are usually language-agnostic.
In a sense you could say that .NET made the Observer pattern 'obsolete' already in .NET 1.0. However, that's not really correct because the pattern didn't become obsolete - the framework just provides a default implementation of the pattern, which means that you rarely have to implement it yourself.
In the same sense you can say that delegates are just anonymous interfaces, so a Func<T>
is an Abstract Factory.
Patterns don't go away just because a language supplies idiomatic support for them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With