Circle–ellipse problem: Difference between revisions

Content deleted Content added
m Added wikilink about class invariants in object-oriented programming.
Adding short description: "Problem in object-oriented programming"
 
(One intermediate revision by one other user not shown)
Line 1:
{{Short description|Problem in object-oriented programming}}
{{More footnotes|date=June 2017}}
The '''circle–ellipse problem''' in [[software development]] (sometimes called the '''square–rectangle problem''') illustrates several pitfalls which can arise when using [[subtype polymorphism]] in [[object modelling]]. The issues are most commonly encountered when using [[object-oriented programming]] (OOP). By definition, this problem is a violation of the [[Liskov substitution principle]], one of the [[SOLID (object-oriented design)|SOLID]] principles.
 
The problem concerns which subtyping or [[inheritance (computerobject-oriented scienceprogramming)|inheritance]] relationship should exist between [[class (programming)|classes]] which represent [[circle]]s and [[ellipse]]s (or, similarly, [[Square (geometry)|squares]] and [[rectangle]]s). More generally, the problem illustrates the difficulties which can occur when a base class contains [[Method (computer science)|methods]] which mutate an object in a manner which may invalidate a (stronger) [[Class invariant|invariant]] found in a derived class, causing the Liskov substitution principle to be violated.
 
The existence of the circle–ellipse problem is sometimes used to criticize object-oriented programming. It may also imply that hierarchical taxonomies are difficult to make universal, implying that situational classification systems may be more practical.