Sections


Main-Menu

header image

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.

encapsulation.gif

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.


Related Articles :



Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Shaadi.com Matrimony - Register for FREE