Wednesday, May 23, 2007

Good Articles On Interface

I have come accross one very good illustration on Interface.
Universal TV Remote Control for all different brands of TV
Power On/Off, Volume high/low, Channel Selection are the common contracts for TV functionalities on a Universal TV Remote Control. I do not need to care about the implementations of every TV. As long as every TV compliance to these contracts, the universal remote control is able to access those functionalities on different brands of TV.
Very Interesting Ambiguity in C# Interface

Tuesday, May 22, 2007

Abstract Class vs. Interface

  • An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods.
  • An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property's signature but no implementation.
  • An abstract class cannot support multiple inheritance, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but only one abstract class.
  • A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class.
  • Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.
  • Abstract classes are faster than interfaces.

http://aspalliance.com/1213_Working_with_Abstract_classes_Sealed_Classes_and_Interfaces_in_C

Monday, May 21, 2007

Why Static Methods?

Why use static methods?
1. Allow users to use those methods without having to create an instance of that class
2. The static class method apply to the class rather than instances
3. Instance methods are instance methods because they rely on the state of the specific object instance.
4. Static methods, e.g. instances() is used to track the number of instantiations at the class level. They are independant of instance states.
5. Useful for utility class (private constructor - no instantiation, but it's easily abused and lead to procedural programming) or factory class.

refer to Static Methods