Encapsulation
Encapsulation
A type of privacy applied to the data and some of the methods (that is, functions or subroutines) in a class, encapsulation ensures that an object can be changed only through established channels (namely, the class’s public methods). Encapsulation means wrapping up of data and associated functions into a single unit(called class). Each object exposes an interface — those public methods, which specify how other objects may read or modify it. An interface can prevent, for example, any caller from adding a list of children to a Dog when the Dog is less than one year old.

Customer, waiter and kitchen are three shielded objects in the ‘cup of coffee’ example. Customer and kitchen do not know each other. The waiter is the intermediary between those two. Objects can’t see each other in an Object Oriented world. The ‘hatch’ enables them to communicate and exchange coffee and money.
Posted in Computer Science, Information Technology, Object Oriented Programming, Object Oriented Programming |
