- Last Updated on 10 January 2011
- Written by Administrator
- Hits: 1450
"Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type."
"Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class."
NOTE: A derived class shall always implement an "is-a" relationship. If you cannot say that the derived class is a special case of the base class, then better drop the idea of deriving it from this base class.
"Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object."
- extending closed source 3rd party
- extension of iEnumerable for LINQ
- keeps the original class code clean
- good readability
- pitfall: if a method with the same name as the extension gets added to the extended class then this method is called instead of the extension without the compiler warning about it.
- impossible if class is sealed
- must implement an "is-a" relationship
Static class method:
- functionally the same as an extension method (only a syntactical difference)