Data Encapsulation

Data Encapsulation

Data encapsulation is the method by which the data and the codes are bound together. This method of data binding is especially prevalent in OSI models of network protocol design. Data encapsulation is carried out to restrict the implementation of and access to a number of functions or methods which can be applied to the ‘members of the class’ or the data.

In this manner, even after the implementation of a number of functions on the class members, the interface itself remains the same. Primary function of this method is to hide the details of the class from the worker and to provide a restricted, defined and pre-set interface to the user. Encapsulation of data hides the details of all functions implemented behind its interface, limiting the user’s access to them, and thus maintains the interface in the same form due to the minimal and restricted number of changes.

This method of data managing is one of the best ways of data protection, because as strongly as it restricts a client’s access to the implementation information, at the same time it allows the user to access the required data in the same controlled setting. Data encapsulation is particularly viable in public working, where the client’s access to private data can prove to be hazardous for the entire system, data encapsulation saves from such a predicament by allowing the users to access the information without giving them the right to modify any of the settings or layout.

Encapsulation is implemented in the working Java program by using the technique of Object Orientation.
For example: User A (Creator) creates codes for a class. The user B uses the same class but uses codes of his/her own choice. Such a scenario would result in a baffling situation in which the use of different codes would end up making the resultant code values of the other user as erroneous and the class will become messed up. This is where data encapsulation comes to the rescue.

To avoid the above stated scenario, user A can create codes of the class maintaining their flexibility but at the same time to make the settings of the instance variable as private, so that any other programmer using the program would be able to use the codes, but not be able to change them according to his/her own will.

Generally, for data encapsulation, variables should be previously hidden or at least protected and afterwards you can use an array of methods, for public access which would ensure that the users get to take advantage of the program. In this way, codes will work for everyone but they would be able to modify it as the settings of the class rest in your hands. In Java program, such codes can be altered by selecting ‘set’ code for Java beans in case of mutators and ‘get’ when dealing with accessory.

Read more:

    Free Cisco CCNA Study Guide

Shortcodes Ultimate

Follow Us