Back

Encapsulation

Idealogic’s Glossary

Encapsulation can be defined as one of the most significant principles of the OOP in which data, which are the attributes, and the operations that are performed on the data, which are the methods, are grouped and contained in one entity or an object, while at the same time, some parts of the object may be inaccessible. This makes it to be a fact that the internal state of the objected is kept safe from the other users and if at all it has to be modified then must do so through some predetermined methods.

In encapsulation, an object’s state and implementation details are only accessible through defined public interface hence, the object state is secured, state change is regulated, there are fewer chances of errors, and the application is easier to comprehend.

Key features of encapsulation include:

Class Fields: These contain information of an object or a class. These fields cannot be accessed easily and are hidden and can only be accessed through the methods of the class.

Methods: These are functions that are created within a class, this means that the functions are part of the class. Can also hide methods by controlling the manner in which the data may be accessed such that only specific operations are allowed.

Access Modifiers: Many programming languages, also contain some access modifiers that define the degree of access to the class fields and methods from outside the class which is an important part of Object Oriented Programming to ensure the Encapsulation.