|
|
||||
|
||||
|
|
||||
|
||||
|
|
|
|
||||
|
||||
|
|
||||
|
||||
|
|
Interface Vs Abstract Class | |
|
There are three differences between an interface and an abstract class:
Actually the first point is the reason for the existence of interfaces in Java: to provide a form of multiple inheritance. In languages with multiple implementation inheritance, an interface would be equivalent to a fully abstract class (a class with only public abstract members). The above differentiation suggests when to use an abstract class and when to use an interface:
In general, prefer interfaces if you don't need to use an abstract class, because they provide more design flexibility. 11/29/07 Stan James: Added two bullets about the ability to add methods to an abstract class without breaking any clients. If you add a method to an interface, you break all implementations. This puts a different spin on "flexibility" in the paragraph above. This distinction did not occur to me on my own; I just ran across it in Kent Becks Implementation Patterns.
See InterfaceVsAbstractClassDiscussion
Other resources: | |