抽象比。接口混乱 [英] Abstraction Vs. Interface Confusion
问题描述
的等等,你开始思考之前,我想清楚了,我的不可以要问接口和抽象之间的日常差异。的
Wait, before you start thinking, I would like to clear that I am NOT going to ask the routine differences between Interface and Abstract.
我已经通过的 MSDN
有人说:
的通过更新基类,所有继承类自动变化更新。的结果
的接口,而另一方面,也不能更换一次创建。如果需要$ B $的新版本B的接口,你必须创建一个全新的界面。的
请参阅这样的: -
See this : -
任何人都可以证明这一点使用下面的例子: -
Can anyone prove this using following example: -
abstract class WashingMachine
{
abstract public void Wash();
}
class Philips : WashingMachine
{
public Philips() { }
override public void Wash(){//Wash code here....}
}
class Samsung : WashingMachine
{
public Samsung() { }
override public void Wash(){//Wash code here....}
}
class Videocon : WashingMachine
{
public Videocon() { }
override public void Wash(){//Wash code here....}
}
现在,如果我增加了以下新的抽象方法的洗衣机 -
Now, If I added following new abstract method in WashingMachine : -
abstract public void Rinse(int loadSize);
如何都继承类(即飞利浦/三星/ Videocon公司)将于的自动 获取与更新的变化
How all inheriting classes (i.e. Philips/Samsung/Videocon) will automatically get updated with the change?
推荐答案
并不会自动更新 - ?你还是要手动的补充冲洗
的每一个实现,每一个从洗衣机
类。
They won't get updated - you still have to manually add an implementation of Rinse
to each and every class that inherits from WashingMachine
.
我相信在MSDN说的是,如果你有一个抽象类定义的非抽象方法和更改的是的方法,所有的从抽象类继承的类将受益于自动更改。
What I believe the MSDN says is that if you have a non-abstract method defined in an abstract class and you change that method, all classes that inherit from the abstract class will benefit from the change automatically.
这篇关于抽象比。接口混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!