Product Design, Manufacturing & Innovation Resources
Lar » Herança (programação orientada a objetos)

Herança (programação orientada a objetos)

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

(Imagem gerada apenas para fins ilustrativos)

A herança é um mecanismo da Programação Orientada a Objetos (POO) onde uma nova classe (subclasse ou classe derivada) é baseada em uma classe existente (superclasse ou classe base), herdando seus atributos e métodos. Isso facilita a reutilização de código e estabelece uma hierarquia natural entre as classes. A subclasse pode estender ou sobrescrever o comportamento herdado, permitindo implementações mais específicas, mantendo, ao mesmo tempo, uma interface comum.

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
Ciência da Computação

Tipo

Sistema abstrato

Interrupção

Substancial

Uso

Uso generalizado

Precursores

  • the concept of hierarchical classification in biology and philosophy
  • data structures that could contain other data structures
  • the need for code reuse in large software systems
  • the design of the simula language, which introduced classes and inheritance

Aplicações

  • GUI widget toolkits (e.g., a ‘button’ class inheriting from a ‘control’ class)
  • frameworks for web development (e.g., controller classes inheriting from a base controller)
  • game development (e.g., ‘orc’ and ‘elf’ classes inheriting from a ‘character’ class)
  • modeling biological classifications
  • creating specialized exception types in linguagens de programação

Patentes:

NA

Ideias de Inovação Potencial

  • extensible plugin architectures for software like wordpress or vscode
  • customizable interface do usuário themes in operating systems
  • transfer learning in neural networks where a base model is extended for a new task
  • versioning systems for software components using class hierarchies
  • generic data access layers that can be specialized for different databases (e.g., sql, nosql)
  • component-based entity systems in game engines
  • layered security protocols inheriting from a base protocol standard
  • extensible financial modeling frameworks
  • customizable robot behaviors inheriting from a base robotics platform
  • domain-specific languages (dsls) built by extending a core language grammar
Related to: inheritance, subclass, superclass, derived class, base class, code reuse, hierarchy, is-a relationship, polymorphism, overriding.

Contexto histórico

Herança (programação orientada a objetos)

1953
1960
1960
1967
1970
1970
1970
1952
1956
1960
1967
1967
1970
1970
1970

(Caso a data seja desconhecida ou irrelevante, por exemplo, "mecânica dos fluidos", é fornecida uma estimativa aproximada de seu surgimento notável)

10º ano aniversário

Imagens em tamanho real e downloads estão disponíveis apenas, 100% gratuitos, para membros registrados.