[amazon_textlink asin=’8120352068|1491987650′ text=’Encapsulation’ template=’ProductLink’ store=’desibanjara22-21|desibanjaraco-21′ marketplace=’IN|UK’ link_id=’f15ac4fb-aa0b-11e8-8a76-3b617ede6a31′] is defined ‘as the process of enclosing one or more items within a physical or logical package’. In other words, Encapsulation is a process of binding data members (variables, properties) and member functions (methods) into a single unit. And Class is the best example of encapsulation.
In [amazon_textlink asin=’9351191494|1292024011′ text=’object oriented programming methodology’ template=’ProductLink’ store=’desibanjara22-21|desibanjaraco-21′ marketplace=’IN|UK’ link_id=’d8a66bef-a9ff-11e8-8a88-a17ed34aad39′], Encapsulation prevents access to implementation details. Through encapsulation a class can hide the internal details of how an object does something. A class can specify how accessible each of its members (variables, properties, and methods) is to code outside of the class or structure. Encapsulation simplifies the interaction between objects. An object can use another object without knowing all its data or how its data is maintained.
Example, an employee object might have name, address, and payment properties. If a HR object wants to use a employee object, it can request the name and address for the employee without needing to know the payment details of the employee object.
With the help of encapsulation, a class can change the internal implementation without hurting the overall functionality of the system.
[amazon_link asins=’9351190900,9352136640,8120352068,007070368X,1787287041,1788398076,1788478924,8126538791|1491988533,1484230175,1491987650,0735615683,1840787198,1430249358,1118336925,0131857258,1788398076,B01E9WKS2O’ template=’ProductGrid’ store=’desibanjara22-21|desibanjaraco-21′ marketplace=’IN|UK’ link_id=’4de50e02-94d2-11e8-9154-f5bdacb2b61e’]