Monday, June 22, 2009

Making choice between Interface and Abstract Class

In which Scenario you will go for Interface or Abstract Class?

Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfacesdo not provide implementation. They are implemented by classes, and defined as separate entities fromclasses. Even though class inheritance allows your classes to inherit implementation from a base class, italso forces you to make most of your design decisions when the class is first published.

Abstract classes are useful when creating components because they allow you specify an invariant levelof functionality in some methods, but leave the implementation of other methods until a specificimplementation of that class is needed. They also version well, because if additional functionality isneeded in derived classes, it can be added to the base class without breaking code.

No comments: