December 2017
Beginner to intermediate
470 pages
12h 29m
English
Encapsulation is about hiding an object's internals from other objects. As the designer of the C++ language, Bjarne Stroustrup, put it, Encapsulation hides information not to faciliate fraud, but to prevent mistakes. By giving other objects a minimal catalog of messages (public methods) that they can send to an object, we are helping them commit less mistakes and avoid getting their hands in tasks that do not pertain them. This, in turn, helps with decoupling objects from themselves and providing cohesiveness within objects.
A common way to think about encapsulation is like when you go to a restaurant—you message the waiter with what you want, and the waiter then delegates the cooking of what you requested to the restaurant's ...