Home  • Programming • C#.NET

What is Encapsulation (or information hiding)?

The encapsulation is the inclusion within a program object of all the resources need for the object to function - basically, the methods and the data. In OOP the encapsulation is mainly achieved by creating classes, the classes expose public methods and properties. The class is kind of a container or capsule or a cell, which encapsulate the set of methods, attribute and properties to provide its indented functionalities to other classes. In that sense, encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system. That idea of encapsulation is to hide how a class does it but to allow requesting what to do. class.gif In order to modularize/ define the functionality of a one class, that class can uses functions/ properties exposed by another class in many different ways. According to Object Oriented Programming there are several techniques, classes can use to link with each other and they are named association, aggregation, and composition. There are several other ways that an encapsulation can be used, as an example we can take the usage of an interface. The interface can be used to hide the information of an implemented class. Collapse | Copy Code IStudent myStudent = new LocalStudent(); IStudent myStudent = new ForeignStudent(); According to the sample above (let’s assume that LocalStudent and ForeignStudent are implemented by the IStudent interface) we can see how LocalStudent and ForeignStudent are hiding their, localize implementing information through the IStudent interface.

Comments 6


good topic.....
thanx
For paragraph use [p] tag and for your code use [code] tag. must be inside the opening and closing tag
use [blockquote] if any important note. Must be inside the opening and closing tag
ok
Good Topic........
About Author
Shakila Jannat
Copyright © 2024. Powered by Intellect Software Ltd