I have been trying to understand the concept of encapsulation and abstraction for quite sometime through many links and youtube videos but still have some confusion related to the concept of encapsulation.
According to the understanding I have related to the concept of Abstraction and Encapsulation is :
Abstraction is showing only what is necessary
Encapsulation says hide complexity
For Eg :
If we have customer application to add a customer and his related details like address by getting a database connection.
In this scenario what I understood about abstraction is showing only addCustomer() method in our class and rest of the operation that we perform when add method is called like getDBConnection() and addCustomerAddress() is hidden inside it.
**
public void addCustomerDetails(){
getDBConnection();
addCustomer();
addCustomerAddress();
}
**
So here whoever is using our class just need to call addCustomerDetails()(i.e.Abstraction) and need not be worried about how db connection is made and how those operations are performed i.e.(Hiding details or Encapsulation)
So far everything is good but somewhere I read another definition related to encapsulation as in :
Data Encapsulation is the process of combining data and functions into a single unit called class.
It can be achieved through keeping data members as private and functions public so that nobody can access it directly.
Kindly tell me what is the correct definition of Encapsulation and how?
Thanks.