6. OOPS Concepts
Encapsulation is one of the fundamental concepts in Object-oriented programming.
It describes the idea of bundling data and methods that work on the data within one unit restricting access to some of the object’s components (variables and methods)
A class is an example of encapsulation as it binds together data and its associated functions under one unit.
Advantages:
- It can prevent the accidental modification or misuse of data by an outside entity.
- It allows programmers better control of how data flows in their programs.
Encapsulation = Abstraction + Information Hiding
Abstraction is used as a technique to identify all the essential characteristics and behaviour of an object and to omit those aspects that are unimportant.
Information Hiding is hiding all the unnecessary information (like implementation details etc.) from outside entities.
A class groups its members into three sections as private, protected and public.
The private and protected members remain hidden from outside world i.e., a class enforces data hiding. The outside world is given only the essential and necessary information through public members, rest of the things remain hidden which is nothing but abstraction.