Content deleted Content added
The old definition was wrong! In the source [1] of definition we can see that THE HIDDING is NOT ENCAPSULATION! The old definition is confusing. Tags: Reverted Visual edit |
This part does not related with encapsulation at all. It could be moved to an article about Anti-patterns or another place but it should not be here. Tags: Reverted Visual edit |
||
Line 1:
{{Short description|Bundling of data}}
In [[object-oriented programming]] (OOP), '''encapsulation''' refers to the bundling of data with the methods that operate on that data. Often that definition is misconstrued to mean that the data is somehow hidden. In Java, you can have encapsulated data that is not hidden at all. So '''encapsulation''' and '''hidding''' are not the same and have different meaning! <ref name="Rogers01" /> Encapsulation is used to hide the values or state of a structured data object inside a [[Class (computer programming)|class]], preventing direct access to them by clients in a way that could expose hidden implementation details or violate state invariance maintained by the methods.
This mechanism is not unique to OOP. Implementations of [[abstract data types]], e.g., [[module (programming)|modules]], offer a similar form of encapsulation. The similarity has been explained by programming language theorists in terms of [[existential types]].<ref>{{harvnb|Pierce|2002|loc=§ 24.2 Data Abstraction with Existentials}}</ref>
|