Content deleted Content added
Jerryobject (talk | contribs) Small WP:EoS WP:COPYEDITs: clarify. WP:LINKs update. |
change paradigms template to navbox (see Template talk:Programming paradigms#too long) |
||
(12 intermediate revisions by 12 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 [[
The most popular and developed model of OOP is a class-based model, instead of an object-based model. In this model, objects are entities that combine ''[[
==Encapsulation==
[[Information hiding|Encapsulation]] prevents users from breaking the [[Invariant (computer science)|invariants]] of the class, which is useful because it allows the implementation of a class of objects to be changed for aspects not exposed in the interface without impact to user code. The definitions of encapsulation focus on the grouping and packaging of related information ([[cohesion (computer science)|cohesion]]) rather than security issues
==Inheritance==
Line 24 ⟶ 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/|
<!-- inline math as LaTeX has poor baseline alignment (better with MathJaX HTML/CSS rendering of LaTeX)
:''Let <math>q(x)</math> be a property provable about objects <math>x</math> of type <math>T</math>. Then <math>q(y)</math> should be provable for objects <math>y</math> of type <math>S</math>, where <math>S</math> is a subtype of <math>T</math>.''
Line 38 ⟶ 30:
==Example languages==
{{
Although [[Simula]] introduced the class abstraction, the canonical example of a class-based language is [[Smalltalk]]. Others include [[PHP]], [[C++]], [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], and [[Objective-C]].
Line 49 ⟶ 41:
{{Reflist}}
{{Programming
{{Types of programming languages}}
{{DEFAULTSORT:Class-Based Programming}}
|