Thursday, January 29, 2009

Interface and abstract C#

Hi,
Here is the situation of using abstract vs interface . you may get some basic idea of using interface and abstract

Consider about the Content Management system we generalize the content as
Articles,Blogs,Reviews

Interface Vs Abstract

Now Consider Content Contains behavior named publish . If the Publish contain some default behavior then the option would be abstract. If the publish is derived and make their own implementation, then no need to implement in base .In this situation the option would be Interface.


If I made content class as Interface then it is difficult to make changes in base class because if I add new method or property in content interface then I have to implement new method in every derive class. This can be overcome in abstract class by creating new method not an abstract type.

In terms of speed abstract is fast then interface because interface requires extra in-direction.

No comments: