Inheritance (object-oriented programming)

inheritancesuperclasssubclassbase classImplementation inheritancederived classsubclassesinheritedclass inheritanceinherit
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation.wikipedia
281 Related Articles

Prototype-based programming

prototype-basedprototypeprototypes
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation.
Prototype-based programming is a style of object-oriented programming in which behaviour reuse (known as inheritance) is performed via a process of reusing existing objects

Object-oriented programming

object-orientedobject orientedobject-oriented programming language
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation.
Languages that support classes almost always support inheritance.

Fragile base class

base classfragile base class problem
Also defined as deriving new classes (sub classes) from existing ones (super class or base class) and forming them into a hierarchy of classes.
The fragile base class problem is a fundamental architectural problem of object-oriented programming systems where base classes (superclasses) are considered "fragile" because seemingly safe modifications to a base class, when inherited by the derived classes, may cause the derived classes to malfunction.

Constructor (object-oriented programming)

Constructor (computer science)constructorscopy constructor
In most class-based object-oriented languages, an object created through inheritance (a "child object") acquires all the properties and behaviors of the parent object (except: constructors, destructor, overloaded operators and friend functions of the base class).
A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers.

Delegation (object-oriented programming)

delegationdelegates
The term "inheritance" is loosely used for both class-based and prototype-based programming, but in narrow use the term is reserved for class-based programming (one class inherits from another), with the corresponding technique in prototype-based programming being instead called delegation (one object delegates to another).
Implicit delegation is the fundamental method for behavior reuse in prototype-based programming, corresponding to inheritance in class-based programming.

Simula

Simula 67Simula ISimula 1
Inheritance was invented in 1969 for Simula.
Simula 67 introduced objects, classes, inheritance and subclasses, virtual procedures, coroutines, and discrete event simulation, and features garbage collection.

Object (computer science)

objectobjectsdata object
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation.
An object is an abstract data type with the addition of polymorphism and inheritance.

Class-based programming

class-basedclass definedclass-based inheritance
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation.
In class-based programming, inheritance is done by defining new classes as extensions of existing classes: the existing class is the parent class and the new class is the child class.

Eiffel (programming language)

EiffelEiffel programming languageEiffel language
For example, in Eiffel, contracts that define the specification of a class are also inherited by heirs.

Design by contract

contractscontractdesign contract
For example, in Eiffel, contracts that define the specification of a class are also inherited by heirs.
Subclasses in an inheritance hierarchy are allowed to weaken preconditions (but not strengthen them) and strengthen postconditions and invariants (but not weaken them).

Class diagram

UML class diagramClassclass diagrams
Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors (realizing an interface), to reuse code and to independently extend original software via public classes and interfaces.
The generalization relationship is also known as the inheritance or "is a" relationship.

Is-a

is asubsumptionis-a'' hierarchies
In some languages inheritance and subtyping agree, whereas in others they differ; in general, subtyping establishes an is-a relationship, whereas inheritance only reuses implementation and establishes a syntactic relationship, not necessarily a semantic relationship (inheritance does not ensure behavioral subtyping).

Has-a

has anhas-a relationship
Composition implements a has-a relationship, in contrast to the is-a relationship of subtyping.

Method overriding

overrideoverriddenoverriding
This process is usually called overriding.
Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

Code reuse

software reusereusere-use
Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors (realizing an interface), to reuse code and to independently extend original software via public classes and interfaces.

C++

C++ programming languageC++98C with Classes
A private method is unoverridable simply because it is not accessible by classes other than the class it is a member function of (this is not true for C++, though).
Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including classes, derived classes, strong typing, inlining and default arguments.

Virtual method table

vtablevirtual tablevirtual function table
Because the exact type of the object being referenced is known before execution, early binding (also called static dispatch) can be used instead of late binding (also called dynamic dispatch), which requires one or more virtual method table lookups depending on whether multiple inheritance or only single inheritance are supported in the programming language that is being used.
Suppose a program contains three classes in an inheritance hierarchy: a superclass, and two subclasses, and.

Multiple inheritance

diamond problemmulti-inheritanceDiamond inheritance problem
Because the exact type of the object being referenced is known before execution, early binding (also called static dispatch) can be used instead of late binding (also called dynamic dispatch), which requires one or more virtual method table lookups depending on whether multiple inheritance or only single inheritance are supported in the programming language that is being used.
Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class.

Encapsulation (computer programming)

encapsulationencapsulateencapsulated
A private method is unoverridable simply because it is not accessible by classes other than the class it is a member function of (this is not true for C++, though).
The authors of Design Patterns discuss the tension between inheritance and encapsulation at length and state that in their experience, designers overuse inheritance.

Object composition

compositionaggregationUser-defined type
Inheritance is contrasted with object composition, where one object contains another object (or objects of one class contain objects of another class); see composition over inheritance.

Virtual function

virtualvirtual methodvirtual functions
If the superclass method is a virtual method, then invocations of the superclass method will be dynamically dispatched.
A subclass of an abstract class can only be instantiated directly if all inherited pure virtual methods have been implemented by that class or a parent class.

Composition over inheritance

Composite reuse principlecompositioncomposition instead of inheritance
Inheritance is contrasted with object composition, where one object contains another object (or objects of one class contain objects of another class); see composition over inheritance.
Composition over inheritance (or composite reuse principle) in object-oriented programming (OOP) is the principle that classes should achieve polymorphic behavior and code reuse by their composition (by containing instances of other classes that implement the desired functionality) rather than inheritance from a base or parent class.

Delegation pattern

delegation
An alternative technique, explicit delegation, requires more programming effort, but avoids the substitutability issue.
In software engineering, the delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as inheritance.

Method (computer programming)

methodsmethodabstract method
The semantics of class inheritance vary from language to language, but commonly the subclass automatically inherits the instance variables and member functions of its superclasses.
C++ also has the concept of virtual functions which are member functions that can be overridden in derived classes and allow for dynamic dispatch.

Subtyping

subtypesubtype polymorphismsupertype
Inheritance should not be confused with subtyping.
Subtyping should not be confused with the notion of (class or object) inheritance from object-oriented languages; subtyping is a relation between types (interfaces in object-oriented parlance) whereas inheritance is a relation between implementations stemming from a language feature that allows new objects to be created from existing ones.