C++ 中的多重继承与Java
当我发现Java中不包含多重继承的原因时,给出的原因是保持“简单性”和“减少复杂性”。 然而,在来自 C++ 背景的 Java 环境中工作,您是否不认为支持多重继承的接口概念使问题变得复杂而不是解决问题?这是否会导致这样的推论:
- 我们一定不能在Java中使用多重继承,并且我们的代码架构应该相应地设计?
- 使用接口的概念进行多重继承,我认为与 st 相比不太有利(至少对我来说)
When i came across the reason why Multiple Inheritance was not included in Java, the reasons given were to keep 'simplicity' and 'reduce complication'.
However working with Java environment coming from a C++ background, don't you think that Interface concept to support multi inheritance has complicated the matter rather than solving it? Does it lead to the inference that:
- We must NOT use multiple inheritance in Java, and our code architecture should be designed accordingly?
- Use concept of Interface for multiple inheritance, which i think is less favorable (atleast for me) compared to the st
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该阅读 Bjarne Stroustrup 关于多重继承的观点:
引自 http://www2.research.att .com/~bs/bs_faq2.html#multiple
You should read Bjarne Stroustrup's point of view about multiple inheritance:
quoted from http://www2.research.att.com/~bs/bs_faq2.html#multiple
多实现继承和多接口继承不是同一回事。
但是,如果要添加多个实现继承,GC 和其他语言的实现将会显着复杂化。
Multiple implementation inheritance and multiple interface inheritance are not the same beasts.
However, it would significantly complicate the GC and other language implementation if they were to add multiple implementation inheritance.
我认为 Java(以及许多其他 OO 语言)设计者的选择主要是受到脆弱基础问题。确实,我们不需要多重继承,但值得注意的是,我们也不需要单一继承。面向对象编程是关于实体的身份。在这方面,继承可以看作是语法糖。
I think the choice of Java (and many other OO languages) designers was mainly motivated by the fragile base problem. It's true we don't need multiple inheritance, but for that's worth to note we don't need single either. Object Oriented programming it's about identities of entities. Inheritance can be seen as syntax sugar in this regard.
java 中的接口概念并非旨在提供多重继承功能。
The interface concept in java is NOT meant for providing multiple inheritance feature.