Encapsulation (computer programming): Difference between revisions

Content deleted Content added
→Cite book, web, harvnb
Rkedge (talk | contribs)
Elevated the definition to improve the flow of the article. The definition will help readers understand the later sections.
Line 9:
 
The features of encapsulation are supported using classes in most object-oriented programming languages, although other alternatives also exist.
 
== General definition ==
 
In general, encapsulation '''is one of the four fundamentals''' of OOP ([[object-oriented programming]]). Encapsulation refers to the bundling of data with the methods that operate on that data.<ref name=Rogers01/> Encapsulation is '''used to hide the values or state of a structured data object inside a class''', preventing unauthorized parties' direct access to them. Publicly accessible methods are generally provided in the class (so-called ''getters'' and ''setters'') to access the values, and other client classes call these methods to retrieve and modify the values within the object.
 
This mechanism is not unique to object-oriented programming. Implementations of [[abstract data types]], e.g. [[module (programming)|modules]], offer a similar form of encapsulation. This similarity stems from the fact that both notions rely on the same mathematical fundamental of an [[existential type]].<ref>{{harvnb|Pierce|2002|loc=§ 24.2 Data Abstraction with Existentials}}</ref>
 
== An information-hiding mechanism ==
Line 156 ⟶ 162:
</source>
 
== General definition ==
 
In general, encapsulation '''is one of the four fundamentals''' of OOP ([[object-oriented programming]]). Encapsulation refers to the bundling of data with the methods that operate on that data.<ref name=Rogers01/> Encapsulation is '''used to hide the values or state of a structured data object inside a class''', preventing unauthorized parties' direct access to them. Publicly accessible methods are generally provided in the class (so-called ''getters'' and ''setters'') to access the values, and other client classes call these methods to retrieve and modify the values within the object.
 
This mechanism is not unique to object-oriented programming. Implementations of [[abstract data types]], e.g. [[module (programming)|modules]], offer a similar form of encapsulation. This similarity stems from the fact that both notions rely on the same mathematical fundamental of an [[existential type]].<ref>{{harvnb|Pierce|2002|loc=§ 24.2 Data Abstraction with Existentials}}</ref>
 
== Encapsulation and Inheritance ==