» 继承(OOP编程)

继承(OOP编程)

1967
  • Kristen Nygaard
  • Ole-Johan Dahl
Programmer coding inheritance in object-oriented programming at a modern office.

继承是面向对象编程 (OOP) 中的一种机制,新类(子类或派生类)基于现有类(超类或基类),继承其属性和方法。继承支持代码复用,并在类之间建立自然的层次结构。子类可以扩展或覆盖继承的行为,从而允许更具体的实现,同时保持通用接口。

Inheritance facilitates an “is-a” relationship between classes. For example, a ‘Dog’ is a type of ‘Animal’. In this scenario, ‘Animal’ would be the superclass, containing general attributes and methods like ‘age’ and ‘eat()’. The ‘Dog’ class would be the subclass, inheriting these properties and adding its own specific ones, like ‘breed’ and ‘bark()’. This avoids code duplication, as the common logic is defined once in the superclass and reused by all its subclasses. Changes made to the superclass are automatically propagated to all subclasses, simplifying maintenance.

There are different types of inheritance, including single inheritance (a class inherits from only one superclass), multiple inheritance (a class inherits from more than one superclass), and multilevel inheritance (a class inherits from another class which itself is a subclass). While powerful, inheritance can also introduce complexity and tight coupling between superclasses and subclasses. Overuse can lead to deep and convoluted hierarchies that are difficult to understand and maintain. Modern design often favors composition over inheritance, where an object contains an instance of another object to achieve code reuse, representing a “has-a” relationship.

UNESCO Nomenclature: 1203
- 计算机科学

类型

抽象系统

中断

Substancial

使用方法

广泛使用

前体

  • 生物学和哲学中的等级分类概念
  • 可以包含其他数据结构的数据结构
  • the need for code reuse in large 软件 系统
  • 模拟语言的设计,引入了类和继承

应用

  • 图形界面 widget toolkits (e.g., a ‘button’ class inheriting from a ‘control’ class)
  • Web 开发框架(例如,从基础控制器继承的控制器类)
  • game development (e.g., ‘orc’ and ‘elf’ classes inheriting from a ‘character’ class)
  • 生物分类建模
  • 在编程语言中创建专门的异常类型

专利:

NA

潜在的创新想法

级别需要会员

您必须是!!等级!!会员才能访问此内容。

立即加入

已经是会员? 在此登录
Related to: inheritance, subclass, superclass, derived class, base class, code reuse, hierarchy, is-a relationship, polymorphism, overriding.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

迎接新挑战
机械工程师、项目、工艺工程师或研发经理
有效的产品开发

可在短时间内接受新的挑战。
通过 LinkedIn 联系我
塑料金属电子集成、成本设计、GMP、人体工程学、中高容量设备和耗材、精益制造、受监管行业、CE 和 FDA、CAD、Solidworks、精益西格玛黑带、医疗 ISO 13485

我们正在寻找新的赞助商

 

您的公司或机构从事技术、科学或研究吗?
> 给我们发送消息 <

接收所有新文章
免费,无垃圾邮件,电子邮件不分发也不转售

或者您可以免费获得完整会员资格以访问所有受限制的内容>这里<

历史背景

(如果日期不详或不相关,例如 "流体力学",则对其显著出现的时间作了四舍五入的估计)。

相关发明、创新和技术原理

滚动至顶部

你可能还喜欢