More on Encapsulation
The notation for object model encapsulation is shown below. Methods are shown at the bottom of the class notation.
Code and data were not always packaged together. At one time, for example, it was necessary to define an age calculation in each application or have a library that contained the age calculation routine. Having an age calculation or any routine, replicated in many applications may make it difficult to ensure that a change in the routine was made everywhere that it is used. Using a library improves this situation if use of the library is enforced. Nevertheless, with a library, you can never be sure which routine is supposed to be used with which data. It is entirely possible to execute the right code on the wrong data or the wrong code on the right data.
Object systems recognize which methods belong to which data. You cannot execute the right method on the wrong data as you could with library systems. The correct execution of methods is called dispatching, and it is handled by the object system. See dispatching.
More on the general topic: Encapsulation