c# 3.0 design patterns
Func<int ,bool> d= x=>x >10?true:false;
int? Nullable<int> hasvalue
To convert back to a non-nullable type, use the as operator. as will return null if it cannot convert the value. For example, int? val = DateTime.Now as int?;
Use the Strategy pattern when…
• Many related classes differ only in their behavior.
• There are different algorithms for a given purpose, and the selection criteria can be codified.
• The algorithm uses data to which the client should not have access.
The role of the Decorator pattern is to provide a way of attaching new state and behavior to an object dynamically.
The object does not know it is being “decorated,” which makes this a useful pattern for evolving systems.
A key implementation point in the Decorator pattern is that decorators both inherit the original class and contain an instantiation of it.
Given that the number of ways of decorating photos is endless, we can have many such new objects.
The beauty of this pattern is that:
• The original object is unaware of any decorations.
• There is no one big feature-laden class with all the options in it.
• The decorations are independent of each other.
• The decorations can be composed together in a mix-and-match fashion.
The Decorator pattern’s key feature is that it does not rely on inheritance for extending behavior.