OOP 派生类和继承类之间的区别?
从OOP的角度来看,派生类和继承类之间有什么区别吗?或者这只是术语?
From an OOP point of view is there any difference between a derived class and an inherited class? Or is it simply terminology?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用继承时,被继承的类称为基类,继承的类称为
派生类。
When using inheritance, the inherited class is called the base class, and the inheriting class is called the
derived class.
术语派生类是首选的C++用语,指的是从另一个类继承的类,在C++用语中,该类称为基类。因此,在 C++ 中,您询问的术语是相同的。
The term derived class is preferred C++ parlance for a class that inherits from another class, which in C++ parlance is called a base class. So in C++ the terms you ask about are identical.
尼尔的回答让我有点困惑,所以我检查了一些公共资源 。
考虑一个基类和一个子类(Java术语中
SubClass扩展BaseClass
),然后所以在我看来,这两个术语定义了类之间相同的关系,但从不同的角度来看。
Neil's answer confused me a bit, and so I checked some public sources.
Consider a Base Class and a Sub Class (
SubClass extends BaseClass
in Java terminology), thanSo in my opinion both terms define the same relationship between to classes but from different perspectives.
Bertran Meyer 的继承术语(面向对象的软件构建,第 464 页):
基本约定和术语
除了“继承人”之外,以下术语也很有用和“父”。
类 C 的后代是直接或间接继承自
C,包括C本身。 (形式上:C,或者递归地,一个
C的继承人。)
C 的祖先是A类,因此C是A的后代>.
在文献中,您还会遇到术语“子类”和“超类”,但是
我们会远离他们,因为他们模棱两可;有时“子类”意味着
继承人(直系后裔),有时用于更一般意义上的适当的
后裔,但并不总是清楚是哪个后裔。此外,我们会看到“子集”
这个词的内涵并不总是合理的。
Inheritance terminology by Bertran Meyer (Object-Oriented Software Construction, p.464):
Basic conventions and terminology
The following terms will be useful in addition to “heir” and “parent”.
A descendant of a class C is any class that inherits directly or indirectly from
C, including C itself. (Formally: either C or, recursively, a descendant of an
heir of C.)
An ancestor of C is a class A such that C is a descendant of A.
In the literature you will also encounter the terms “subclass” and “superclass”, but
we will stay away from them because they are ambiguous; sometimes “subclass” means
heir (immediate descendant), sometimes it is used in the more general sense of proper
descendant, and it is not always clear which. In addition, we will see that the “subset”
connotation of this word is not always justified.
也许有趣,如果你重写一个方法,在 Delphi 中你可以写:
而不是
maybe interesting, if you override a method, in Delphi you write:
instead of