Content deleted Content added
No edit summary |
mNo edit summary |
||
Line 6:
Some programming language researchers and academics use the first meaning alone or in combination with the second as a [[Object oriented programming#features|distinguishing feature of object oriented programming]], while other programming languages which provide [[Closure_(computer_programming)|lexical closures]] view encapsulation as a feature of the language orthogonal to object orientation.
The second definition is motivated by the fact that in many OOP languages hiding of components is not automatic or can be overridden; thus, [[information hiding]] is defined as a separate notion by those who prefer the second definition.<!-- this is based on all the refs given above, so no inline cite here-->
== As information hiding mechanism ==
Line 13:
Hiding the internals of the object protects its integrity by preventing users from setting the internal data of the component into an invalid or inconsistent state. A benefit of encapsulation is that it can reduce system complexity, and thus increases [[robustness (computer science)|robustness]], by allowing the developer to limit the interdependencies between software components.
Almost always, there is a way to override such protection - usually via reflection API (Ruby, Java, C#, etc.), sometimes by mechanism like name mangling ([[Python (programming language)|Python]]), or special keyword like <code>friend</code> in C++. This access is often necessary for debuggers, serialization, unit testing, but not uncommonly in normal code when <code>private</code> was overeagerly applied. [http://www.davidarno.org/2010/07/22/why-the-private-keyword-is-the-modern-day-goto/]
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 fundament of an [[existential type]].<ref>Pierce (2002), Section 24.2 "Data Abstraction with Existentials"</ref>
== In combination ==
|