There is always a debate over using either an interface or an abstract class. The following are a few rules to follow when deciding which way to go:
- Is-A versus Can-Do: Any type can inherit from one parent class only and multiple interfaces. If for the derived class B you can't say B Is-an A (A is the base type), contradictory. Interfaces imply a Can-Do relationship. If the Can-Do functionality is applicable to different object types, go with an interface implementation. For example, for both FileOutputStream and ByteOutputpuStream (and any of the other sibling implementations available), you can say they have an Is-A relationship with java.io.OutputStream. Hence, you will see that OutputStream is an abstract class providing common implementations to all objects that represent a writable stream. However, Autocloseable , which represents an object...