Content deleted Content added
change paradigms template to navbox (see Template talk:Programming paradigms#too long) |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 1:
{{Short description|Style of object-oriented programming where inheritance is based on classes}}
{{Refimprove|date=February 2013}}
'''Class-based programming''', or more commonly '''class-orientation''', is a style of [[object-oriented programming]] (OOP) in which [[inheritance (object-oriented programming)|inheritance]] occurs via defining ''[[class (computer programming)|class]]es'' of [[object (computer science)|object]]s, instead of inheritance occurring via the objects alone (compare [[prototype-based programming]]).
Line 16:
The defining feature of inheritance is that both interface and implementation are inherited; if only interface is inherited, this is known as [[interface inheritance]] or ''subtyping.'' Inheritance can also be done without classes, as in [[prototype-based programming]].
==Critique
Class-based languages, or, to be more precise, [[typed language]]s, where [[Subclass (computer science)|subclassing]] is the only way of [[subtyping]], have been criticized for mixing up implementations and interfaces—the essential principle in object-oriented programming. The critics say one might create a bag class that stores a [[Collection class|collection]] of objects, then extend it to make a new class called a set class where the duplication of objects is eliminated.<ref>{{cite web|first=Oleg|last=Kiselyov|title=Subtyping, Subclassing, and Trouble with OOP|url=http://okmij.org/ftp/Computation/Subtyping/|access-date=7 October 2012}}</ref><ref>{{cite web|title=A set cannot be a subtype of a bag|last=Ducasse|first=Stéphane|url=http://stephane.ducasse.free.fr/Resources/LecturesInPowerpoint/STOOP-416-LSP.ppt|access-date=7 October 2012}}</ref> Now, a function that takes an object of the bag class may expect that adding two objects increases the size of a bag by two, yet if one passes an object of a set class, then adding two objects may or may not increase the size of a bag by two. The problem arises precisely because subclassing implies subtyping even in the instances where the principle of subtyping, known as the [[Liskov substitution principle]], does not hold. [[Barbara Liskov]] and [[Jeannette Wing]] formulated the principle succinctly in a 1994 paper as follows:
<!-- inline math as LaTeX has poor baseline alignment (better with MathJaX HTML/CSS rendering of LaTeX)
Line 41:
{{Reflist}}
{{Programming
{{Types of programming languages}}
{{DEFAULTSORT:Class-Based Programming}}
|