Almost every Java book I read talks about using the interface as a way to share state and behaviour between objects that when first ‘constructed’ did not seem to share a relationship.
However, whenever I see architects design an application, the first thing they do is start programming to an interface. How come? How do you know all the relationships between objects that will occur within that interface? If you already know those relationships, then why not just extend an abstract class?
Programming to an interface means respecting the ‘contract’ created by using that interface. And so if your
IPoweredByMotorinterface has astart()method, future classes that implement the interface, be theyMotorizedWheelChair,Automobile, orSmoothieMaker, in implementing the methods of that interface, add flexibility to your system, because one piece of code can start the motor of many different types of things, because all that one piece of code needs to know is that they respond tostart(). It doesn’t matter how they start, just that they must start.