> For the complete documentation index, see [llms.txt](https://dotnetweb30-ke.gitbook.io/ke/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dotnetweb30-ke.gitbook.io/ke/design/ood/encapsulation.md).

# Encapsulation

{% hint style="success" %}
**Encapsulation** is approach for restricting direct access to some of the data structure elements (fields, properties, methods, etc)
{% endhint %}

*Abstraction* and *encapsulation* are complementary concepts: Abstraction focuses on the observable behavior of an object, whereas encapsulation focuses on the implementation that gives rise to this behavior.

Encapsulation is most often achieved through information hiding (not just data hiding), which is the process of hiding all the secrets of an object that do not contribute to its essential characteristics; typically, the structure of an object is hidden, as well as the implementation of its methods.

![](https://lh5.googleusercontent.com/cKQsE2Cu9kJUeb1y65oAbScsjIT6Uj9YVj9FKCsmooKmQbiN78UrAgq5eOYEUwcVWiY0jHvifUxiw2xF0x8Q5IFnEkZT_QUbsrsEISIc_xlwaxrt18U4CHI0uMMaG9lZB5xcV-KMzUyBZvc1EA)

Encapsulation provides explicit barriers among different abstractions and thus leads to a clear separation of concerns. Objects at one level of abstraction are shielded from implementation details at lower levels of abstraction.
