Encapsulation (computer programming): Difference between revisions

Content deleted Content added
No edit summary
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 usage like <code>friend</code> in C++.
 
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>