Understanding Encapsulation And Abstraction

Encapsulation

  1. Reduce Complexity
  2. Hide the information which you don't want to share with the outside world.

So, in simple words, encapsulation means hiding information.

Abstraction

  1. Show only the essential features.
  2. Hide internal process.

So, in simple words, abstraction means hiding implementation.

Let's see an example to understand encapsulation and abstraction.

class CustomerClass {
    public void AddCustomer(string name) {
        validate("uttam");
        savedata("uttam");
    }
    private bool validate(string name) {
        //Validate name
        return true;
    }
    private bool savedata(string name) {
        //Save to database
        return true;
    }
}
class Program {
    static void Main(string[] args) {
        CustomerClass p = new CustomerClass();
        p.AddCustomer("uttam");
    }
}

Where are Encapsulation and Abstraction in the above example?

Encapsulation

When we make functions validate and savedata access modifier to private then we are doing encapsulation.

Abstraction

We are allowing function AddCustomer to be accessed from the outside world and hiding the internal process like validate and savedata is abstraction.