Saturday, June 14, 2014

Abstract Classes vs Interfaces

In order to decide on what to choose between an abstract class or an interface, its important to know the strengths and weaknesses of each. Based on the needs that match the requirements, once can choose between interfaces and abstract classes.



Abstract Classes
Interfaces
May contain implementation code. However, it must have at least one abstract member.
Must not contain any implementation code
A class may inherit from a single base class
A class may implement multiple interfaces
Members have to have access modifiers
Members are automatically public so should not have access modifiers. In fact declaring access modifiers with members would lead to compile time exception.
May contain
·         Constructors
·         Destructors
·         Fields
·         Properties
·         Methods
·         Events
·         Indexers
May contain
·         Properties
·         Methods
·         Indexers
·         events

No comments:

Post a Comment