|
Java™ by example!
|
|
|
When should I use interfaces as opposed to abstract base classes?
An interface encapsulates a set of attributes and services without specifying how these services are implemented. An abstract class lies in between a normal class an an interface. It defines a set of services that are to be implemented as well as some fully implemented services. In general you should favor interfaces over abstract classes. Java doesn't support multiple inheritance so the only way to adhere to a contract that an abstract class exposes is to extend from this class. An interface is much more flexible and is to be used when the interface is likely to be reused at a later stage in the process. If you need some default implementation or behavior for all the classes that adhere to a certain contract, use abstract classes. There are several articles on this topic. Check out the links below!
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|