Encapsulation vs Abstraction in OOPs

Hi Folks,

Could anyone make me clear the difference between encapsulation and abstraction.
In my POV the difference between Encapsulation and Abstraction is....
Encapsulation : Encapsulation is the way of integration like object+dataMember into a single unit. Where the data is hidden...

Abstraction : Hiding the implementation of the business logic...

Need a good guidance over this topic.

Replies

  • Sanyam Khurana
    Sanyam Khurana
    Nikumbh
    Hi Folks,

    Could anyone make me clear the difference between encapsulation and abstraction.
    In my POV the difference between Encapsulation and Abstraction is....
    Encapsulation : Encapsulation is the way of integration like object+dataMember into a single unit. Where the data is hidden...

    Abstraction : Hiding the implementation of the business logic...

    Need a good guidance over this topic.

    See, Encapsulation is an OOP feature, when you bind all your data members and associated member functions, under a single unit.
    This is done through Class.

    Eg:
    class test
    {
    int a,
    char b[10];
    public:
    int check();
    }
    Here, a and b are data members, where as check is some method, so you have all this defined under a single unit, ie class here.
    This is encapsulation.

    Abstraction refers to data hiding, which is done through access levels namely private, public and protected for C++ , and for java there is private, protected, public and default levels.

    Sometimes, we want to give only essential details, without giving out all the background details.
    In the above example, class by default has a private access level, so the data members, a and b are kept private, where as the function is made public.

    These things sound more clear when you learn about inheritance.
  • vikaskumar11233
    vikaskumar11233
    Encapsulation means hiding unimportant data whereas Abstraction means wrapping up of data.
  • Sanyam Khurana
    Sanyam Khurana
    vikaskumar11233
    Encapsulation means hiding unimportant data whereas Abstraction means wrapping up of data.
    Are you sure, about this..?

    vikaskumar11233
    Encapsulation means hiding unimportant data
    You have mix matched...
    And why would someone, hide UNIMPORTANT data..?
  • Alok mishra
    Alok mishra
    Encapsulation is about keeping things (data and code to manipulate that data) in a single unit called class . There are access specifiers (private, protected,public and default) that give encapsulation its importance .
    Abstraction is undoubtedly information hiding as most often we are concerned only about outcome not to the entire internal architecture.
    Like while driving car ,driver pushes the break and car stops he doesnt even bother what its internal mechanism was.
    More precisely abstraction is used to reduce complexity.
  • Anoop Kumar
    Anoop Kumar
    Do not confuse with Abstract keyword in java. that is something else.

    Abstraction: Car break, as a user you don't have to know about every detail of how break works. you just apply the break and that's it. Of-course if you want you can see and how they are being used.
    In programming terms API's are best example of abstraction. you just have to know how to call api. like api's for barcode reading, encryption etc.

    Encapsulation: Totally wrapped system like engine, binding all engine component into one unit. you may not have access to internal system to see what inside it, unless a car mechanic will open it and repair it.
  • Nikumbh
    Nikumbh
    So, can I take this as.....
    Abstraction : Is hiding the implementation of a class dataMember(most probably methods inside the class). ie., interface in java
    Encapsulation : Is apart from wrapping up object + datamember, hiding the data inside the dataMember. ie., encapsulation uses the data hiding concept.

    For example StringBuffer class in java. When we create an instance for StringBuffer.
    like,
    StringBuffer sampleString=new StringBuffer("My String");

    Here the abstracted information is

    * size of the sampleString. (Data hidden)

    sampleString.append("appended String 2");

    Now the StringBuffer pointer moved to the end of the "My String" with the help of size of the sampleString's last index and start appending the new string.
    correct me if i'm wrong.
  • Anoop Kumar
    Anoop Kumar
    encapsulation is binding things together and preventing from unauthorized access.

    Yes, for your example abstraction looks good.
  • Nikumbh
    Nikumbh
    @#-Link-Snipped-# : The example what I explained above is for data hiding. Encapsulation rather does data hiding over the implementation part from interface, apart from encapsulating the interface with the implementation.

    There are two mechanism to conduct ABSTRACTION.

    1.Encapsulation
    2.Polymorphism


    correct me if i'm wrong.

You are reading an archived discussion.

Related Posts

All of us who had a chance to be at hostel would have experienced those beautiful memories. The memories include happier birthday’s , cultural , Hostel day, and many fights....
I had surfed over the net for New car releases in Frankfurt and I am tired of counting the cars.So I had made a decision to post some cars which...
Most popular inventions were never done intentionally, the reason being no one at that time was actually gunning for those. X-rays, Ink-Jet printers, Microwave ovens and many more were results...
Hi, I'm currently working on a project which requires the usage of microcontroller and I need help. The project's objective is to read current(ampere) from vehicle electrical system and activates...
Blackberry has today launched a new smartphone called the Blackberry 9720. The new backlit QWERTY keypad featuring smartphone has 2.8 inch screen with a 4:3 aspect ratio. Alongside the 35-keyed...