Programming to an interface means respecting the "contract" created by using that interface. And so if your IPoweredByMotor
interface has a start()
method, future classes that implement the interface, be they MotorizedWheelChair
, Automobile
, or SmoothieMaker
, 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 to start()
. It doesn't matter how they start, just that they must start.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…