Two primary concepts in object-oriented programming are abstraction and encapsulation. Abstraction is the process of reducing complex real-world entities down to their fundamental characteristics and presenting them in a simple manner. It points out the importance of keeping irrelevant information hidden and giving consumers access to only the necessary information.
Abstraction in programming enables you to design abstract classes or interfaces that specify the shared characteristics and operations of a collection of related objects. It offers a generalized and simplified way to represent real-world entities, concepts, or systems.
The main abstraction points are:
defining a common set of methods and properties by creating abstract classes or interfaces.
internal implementation that is kept secret.
Encapsulation is the method of merging data and methods into a single entity, referred to as a class. The methods (functions or behaviors) that operate on the data are combined with the data (attributes or properties) and are contained within a class.
Encapsulation is used to safeguard an object's internal state and grant regulated access to it. It restricts access to and modification of data, enabling things to preserve their integrity. You can impose data validation, set access limitations, and guarantee consistency by encapsulating data and methods.
The main ideas encapsulated are:
creating a class from relevant data and techniques.
use access modifiers (such as public, private, and protected) to regulate access to internal data.