Difference between Encapsulation and Abstraction

后端 未结 15 1122
萌比男神i
萌比男神i 2020-12-07 07:21

I had an interview today. I had a question from OOP, about the difference between Encapsulation & Abstraction?

相关标签:
15条回答
  • 2020-12-07 08:21

    This image sums pretty well the difference between both:

    Source here

    0 讨论(0)
  • 2020-12-07 08:22

    Abstraction: what are the minimum functions and variables that should be exposed to the outside of our class.

    Encapsulation: how to achieve this requirement, meaning how to implement it.

    0 讨论(0)
  • 2020-12-07 08:24

    difference in both is just the View Point
    Encapsulation word is used for hiding data if our aim is to prevent client seeing inside view of our logic

    Abstraction word is used for hiding data if our aim is to show our client a out side view

    Outside view means that let suppose

    BubbleSort(){
    //code 
    swap(x,y);
    }
    

    here we use swap in bubble sort for just showing our client what logic we are applying, If we replace swap(x,y) with whole code here, In a single instance he/she can't understand our logic

    0 讨论(0)
提交回复
热议问题