1

The title says it all, I am bit confused as I was asked a question that Information handling in term of OOP is abstraction or encapsulation? I opted for abstraction but still I am confused because in encapsulation we also hide the fields and in abstraction we hide the details. Any help in this regard

4 Answers4

1

It may help if you think of encapsulation as one of the tools used to create abstraction. See the wikipedia entry for encapsulation here http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)

David Wilkins
  • 574
  • 4
  • 19
1

Abstraction generally hides information, while Encapsulation separates the changeable data from the unchanged one. In this way, Encapsulation helps to achieve the Open Closed Principle.

Wasif Hossain
  • 3,900
  • 1
  • 18
  • 20
1

Here is a nice answer that I think it clears the confusion

Encapsulation has two faces; data abstraction and information hiding. Data abstraction is a type seen from the outside. Information hiding is a type seen from the inside.

  • Abstraction focuses on the outside view of an object (i.e. the interface)
  • Encapsulation (information hiding ) prevents clients from seeing its inside view, where the behavior of the abstraction is implemented
Community
  • 1
  • 1
humam
  • 191
  • 5
0

Encapsulation = Hiding the Complexities / information

Abstraction = A (somewhat) defined way to handle complexities, using encapsulation

sallushan
  • 1,134
  • 8
  • 16
  • Abstraction is handling complexities? it doesn't hide your low level details? –  Mar 30 '14 at 09:51
  • You are right I edited my answer, I was actually talking about the larger scope of functionality, but its better this way – sallushan Mar 30 '14 at 09:57