first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

“Interface vs Abstract Class”; StackOverflow.com

In .NET (similar for Java):

* interfaces can have no state or implementation
* a class that implements an interface must provide an implementation of all the methods of that interface
* abstract classes may contain state (data members) and/or implementation (methods)
* abstract classes can be inherited without implementing the abstract methods (though such a derived class is abstract itslef)
* interfaces may be multiple-inherited, abstract classes may not (this is probably the key concrete reason for interfaces to exist separately from abtract classes - they permit an implementation of multiple inheritance that removes many of the problems of general MI).

As general OO terms, the differences are not necessarily well-defined. For example, there are C++ programmers who may hold similar rigid definitions (interfaces are a strict subset of abstract classes that cannot contain implementation), while some may say that an abstract class with some default implementations is still an interface or that a non-abstract class can still define an interface.

  1. An interface can be seen as a pure Abstract Class, is the same, but despite this, is not the same to implement an interface and inheriting from an abstract class. When you inherit from this pure abstract class you are defining a hierarchy -> inheritance, if you implement the interface you are not, and you can implement as many interfaces as you want, but you can only inherit from one class.

  2. You can define a property in an interface, so the class that implements that interface must have that property.

For example:

public interface IVariable
{
    string name {get; set;}
}

The class that implements that interface must have a property like that.

hope this helps!

[http://stackoverflow.com/questions/761194/ interface-vs-abstract-class-general-oo]

mod date: 2009-08-22T01:55:15.000Z