Object-oriented programming – link to semantics

It is not possible to add the new link because it would replace an existing, longer link.

Line 2: Line 2:
{{See also|Object-oriented design}}<!-- not "further" because that article is mostly blather and does not even mention this -->
{{See also|Object-oriented design}}<!-- not "further" because that article is mostly blather and does not even mention this -->


People often think that if one class inherits from another, it means the subclass "[[is a]]" more specific version of the original class. This presumes the [[program semantics]] are that objects from the subclass can always replace objects from the original class without problems. This concept is known as [[behavioral subtyping]], more specifically the [[Liskov substitution principle]].
People often think that if one class inherits from another, it means the subclass "[[is a]]" more specific version of the original class. This presumes the program [[semantics]] are that objects from the subclass can always replace objects from the original class without problems. This concept is known as [[behavioral subtyping]], more specifically the [[Liskov substitution principle]].


However, this is often not true, especially in programming languages that allow [[mutable]] objects, objects that change after they are created. In fact, [[subtype polymorphism]] as enforced by the [[type checker]] in OOP languages cannot guarantee behavioral subtyping in most if not all contexts. For example, the [[circle-ellipse problem]] is notoriously difficult to handle using OOP's concept of inheritance. Behavioral subtyping is undecidable in general, so it cannot be easily implemented by a compiler. Because of this, programmers must carefully design class hierarchies to avoid mistakes that the programming language itself cannot catch.
However, this is often not true, especially in programming languages that allow [[mutable]] objects, objects that change after they are created. In fact, [[subtype polymorphism]] as enforced by the [[type checker]] in OOP languages cannot guarantee behavioral subtyping in most if not all contexts. For example, the [[circle-ellipse problem]] is notoriously difficult to handle using OOP's concept of inheritance. Behavioral subtyping is undecidable in general, so it cannot be easily implemented by a compiler. Because of this, programmers must carefully design class hierarchies to avoid mistakes that the programming language itself cannot catch.