Hogar » Polimorfismo (programación)

Polimorfismo (programación)

1967
  • Christopher Strachey
Computer programming workspace demonstrating polymorphism with code snippets.

Polymorphism, from Greek for “many shapes,” allows objects of different classes to be treated as objects of a common superclass. It enables a single interface, such as a method name, to be used for a general class of actions. The specific action is determined by the exact type of the object at runtime. This is often achieved through method overriding.

Polymorphism is a powerful concept that allows for writing flexible and decoupled code. The most common form in OOP is subtype polymorphism, which is enabled by inheritance and método overriding. When a subclass provides a specific implementation for a method that is already defined in its superclass, it is called overriding. A variable of the superclass type can refer to an object of any of its subclasses. When a method is called on this variable, the version of the method that gets executed is the one belonging to the object’s actual class, not the variable’s type. This decision is made at runtime, a process known as dynamic dispatch or late binding.

For example, consider a superclass ‘Shape’ with a method ‘calculateArea()’. Subclasses like ‘Circle’ and ‘Rectangle’ can inherit from ‘Shape’ and provide their own specific implementations of ‘calculateArea()’. A program can then have a list of ‘Shape’ objects, containing both ‘Circle’ and ‘Rectangle’ instances. When iterating through the list and calling ‘calculateArea()’ on each element, the correct formula will be used for each shape automatically. This eliminates the need for long ‘if-else’ or ‘switch’ statements to check the type of each object, leading to cleaner, more extensible code. New shapes can be added to the system without modifying the code that processes them.

UNESCO Nomenclature: 1203
- Informática

Tipo

Sistema abstracto

Disrupción

Incremental

Utilización

Uso generalizado

Precursores

  • El concepto de punteros de función en lenguajes como C
  • conceptos de programación genéricos
  • herencia, que proporciona la jerarquía de clases necesaria para el polimorfismo de subtipos
  • the need for flexible and extensible software sistemas

Aplicaciones

  • drawing different shapes (‘circle’, ‘square’) using a single ‘draw()’ method call
  • processing various document types (‘pdf’, ‘word’) with a generic ‘print()’ function
  • implementing interfaz de usuario event handlers
  • Colecciones genéricas que pueden contener objetos de tipos diferentes pero relacionados
  • marcos de inyección de dependencia

Patentes:

NA

Posibles ideas innovadoras

Membresía obligatoria de Professionals (100% free)

Debes ser miembro de Professionals (100% free) para acceder a este contenido.

Únete ahora

¿Ya eres miembro? Accede aquí
Related to: polymorphism, overriding, dynamic dispatch, late binding, subtype, interface, abstraction, oop, method overriding, runtime.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

DISPONIBLE PARA NUEVOS RETOS
Ingeniero Mecánico, Gerente de Proyectos, Ingeniería de Procesos o I+D
Desarrollo eficaz de productos

Disponible para un nuevo desafío a corto plazo.
Contáctame en LinkedIn
Integración de electrónica de metal y plástico, diseño a coste, GMP, ergonomía, dispositivos y consumibles de volumen medio a alto, fabricación eficiente, industrias reguladas, CE y FDA, CAD, Solidworks, cinturón negro Lean Sigma, ISO 13485 médico

Estamos buscando un nuevo patrocinador

 

¿Su empresa o institución se dedica a la técnica, la ciencia o la investigación?
> Envíanos un mensaje <

Recibe todos los artículos nuevos
Gratuito, sin spam, correo electrónico no distribuido ni revendido.

o puedes obtener tu membresía completa -gratis- para acceder a todo el contenido restringido >aquí<

Contexto histórico

(si se desconoce la fecha o no es relevante, por ejemplo "mecánica de fluidos", se ofrece una estimación redondeada de su notable aparición)

Invención, innovación y principios técnicos relacionados

Scroll al inicio

También te puede interesar