Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encapsulation..most precise description?

Tags:

c#

oop

I know that encapsulation means something like that one object should not have direct access to members of different objects...but I guess it relates to public fields? I assume public methods do not break encapsulation..? I am just not clear here and would be glad for any explanation.

like image 574
Miria Avatar asked May 12 '11 19:05

Miria


1 Answers

Encapsulation is that you drive your car by:

  • turning the ignition key
  • steering the wheel
  • changing the gears (if not automatic)
  • adding the fuel

and not by:

  • igniting the fuel in the cylinders
  • friction-ing tires and ground
  • and so on...

Expose (make public) WHAT and hide (make private) HOW. Now, you're encapsulating.

:)

like image 102
Daniel Mošmondor Avatar answered Sep 22 '22 11:09

Daniel Mošmondor