OOP 派生类和继承类之间的区别?

发布于 2024-08-17 21:26:22 字数 41 浏览 10 评论 0原文

从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

韵柒 2024-08-24 21:26:22

使用继承时,被继承的类称为基类,继承的类称为
派生类。

When using inheritance, the inherited class is called the base class, and the inheriting class is called the
derived class.

初吻给了烟 2024-08-24 21:26:22

术语派生类是首选的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.

時窥 2024-08-24 21:26:22

尼尔的回答让我有点困惑,所以我检查了一些公共资源

考虑一个基类和一个子类(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), than

  • the Sub Class derives Base Class (Sub Class is a derived class of Base Class) and
  • the Sub Class inherits from Base Class (Base Class is a/the inherited class of Sub Class)

So in my opinion both terms define the same relationship between to classes but from different perspectives.

北陌 2024-08-24 21:26:22

Bertran Meyer 的继承术语(面向对象的软件构建,第 464 页):

基本约定和术语

除了“继承人”之外,以下术语也很有用和“父”。

C后代是直接或间接继承自
C,包括C本身。 (形式上:C,或者递归地,一个
C的继承人。)
C祖先A类,因此CA的后代>.

在文献中,您还会遇到术语“子类”和“超类”,但是
我们会远离他们,因为他们模棱两可;有时“子类”意味着
继承人(直系后裔),有时用于更一般意义上的适当的
后裔,但并不总是清楚是哪个后裔。此外,我们会看到“子集”
这个词的内涵并不总是合理的。

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.

不回头走下去 2024-08-24 21:26:22

也许有趣,如果你重写一个方法,在 Delphi 中你可以写:

inherited; // so "inherited" is the base class

而不是

base.BaseImplementation(); // C#

maybe interesting, if you override a method, in Delphi you write:

inherited; // so "inherited" is the base class

instead of

base.BaseImplementation(); // C#
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文