Week 8 Flashcards
is defined as the wrapping up of data and information in a single unit. It is defined as binding together the data and the functions that manipulate them.
Encapsulation
What are the two important property of Encapsulation
Data Protection
Information Hiding
Encapsulation protects the internal state of an object by keeping its data members private. Access to and modification of these data members is restricted to the class’s public methods, ensuring controlled and secure data manipulation.
Data Protection
Features of Encapsulation
*We can not access any function from the class directly. We need an object to access that function that is using the member variables of that class.
*The function which we are making inside the class must use only member variables, only then it is called encapsulation.
*If we don’t make a function inside the class which is using the member variable of the class then we don’t call it encapsulation.
*Encapsulation improves readability, maintainability, and security by grouping data and methods together.
*It helps to control the modification of our data members.
Encapsulation hides the internal implementation details of a class from external code. Only the public interface of the class is accessible, providing abstraction and simplifying the usage of the class while allowing the internal implementation to be modified without impacting external code
Information Hiding
also leads to data abstraction.
Encapsulation
also hides the data, as in the above example, the data of the sections like sales, finance, or accounts are hidden from any other section. To understand how to implement encapsulation effectively in C++, check out the C++ Course, which provides detailed explanations and examples.
Encapsulation
means that the member function or data member can only be accessed by other member functions of the same class.
Private
means that the member function or data member can be accessed by other member functions of the same class or by derived classes.
Protected
means that the member function or data member can be accessed by any code.
Public