父类的子节点与VB.NET或C#中的基类的派生有什么区别?

Gra*_*ate 9 c# vb.net parent-child derived-class

在询问问题调用一个方法,该方法需要在VB.NET中将类型化为基类的派生类实例或 Stack Overflow上的C#,我被告知在提问时我使用了错误的术语.我使用过"父母"和"孩子",我应该用"base"和"derived"代替.

我一直无法找到差异的良好描述.

到目前为止,这就是我所知道的(或者我认为)

父类包含子类.派生类继承自基类的位置.

它们是相似的,因为子(或派生)可以访问父(或基)属性和方法(如果允许).

它们是不同的,因为您可以以形式引用子类的属性Parent.Child.Property.而你不能用派生类做到这一点.

有什么区别,在什么情况下应该使用另一个?

Cod*_*aos 7

parent and child are more abstract relations. They are used to describe hierarchy, and thus can be used in all kinds of trees (or sometimes DAGs).
The tree of class inheritance is one such tree, so calling them parent and child is not wrong.
This terminology is often used with other kinds of trees, such as nested GUI controls, directory structures,...

basederived仅用于继承,因此更精确.这个术语是首选,因为它不那么模糊.


D S*_*ley 5

在两种情况下都使用父/子.它可以用来描述你所提到的"包含"关系(Parent.Child.Property),或者它可以表示派生类(也称为子类).

底线是 - 了解父/子的含义,你必须知道背景.

在任何情况下,两个概念(继承与封装)之间的差异可以被认为是"is-a"和"has-a"关系.

  • 动物(遗传)
  • 汽车发动机(封装)