Skip to content

The difference between the Abstract Class and the Interface.

AbderRahman

Asked Aug 8, 2006, 12:24 AM EDT1 answer
Share
LinkedInX

I know that the Abstract Class looks like the Interface one.
but I'am sure that there is a certain difference between them.
so, i wish from you to provide me with those differences.

Thanks in advanced.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Simply put, an Interface is a contract - it is purely defining methods or fields that must be implemented....while an Abstract class will usually provide some functionality.

    (I've lifted this the below from a Java site!!)
    An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that have to add on to the their code to be able to use your package.

    An abstract class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation. The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed their own class hierarchy independently.

    Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.
    0