抽象比。接口混乱 [英] Abstraction Vs. Interface Confusion

查看:1138
本文介绍了抽象比。接口混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

等等,你开始思考之前,我想清楚了,我的不可以要问接口和抽象之间的日常差异。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆