Concept of Data Encapsulation

Added on - 25 Sep 2019

  • 10


  • 2878


  • 104


  • 0


Showing pages 1 to 3 of 10 pages
Data EncapsulationNowadays it is a very important concept to hide confidential data from a hacker or suchcyber crimes. Industries are using encapsulation method to control the transmitted data across thenetwork. Therefore, data Encapsulation is one of the most popular topics in Computer science inrecent years. Everyone can use the implantation details without any side effects. Encapsulatedcode gives the power to everyone.About Data Encapsulation:Object-Oriented Programming is a model for programming languages where programsare written by organizing it into objects and data instead of functions. Object-OrientedProgramming has some properties like Encapsulation, Abstraction, Inheritance, andPolymorphism. The mechanism of hiding implemented details, as well as functions, is calledencapsulation.In the implementation level, the code and data are wrapped up with a single unit. Dataencapsulation is used to set a restricted layer of functions. A user cannot operate the restrictedset. Data is kept inside a class. Each object state and implementation are kept inside any classprivately. Other objects cannot make any change for private methods. Only public methods canbe called by the other classes.The best example that defines data encapsulation in a proper way is Class. In the class,the designer determines the mechanism way in which the action performed. The designer shouldkeep in mind the matter about flexibility or restrictiveness for hiding data. Therefore, theintegrity of data is guaranteed with encapsulation. The private fields as well as the publicbehaviour toward class help to achieve the goal.Example-public class Student{private string studentName;public string getname(){return studentName;
}public void setname(string inName){studentName = inName;}}public static void main(){string sName ="Jack&quot";Student obj = new Student();obj.setname(sName);System.Console.WriteLine("Name :"; + obj.getname());}In this example, getname() refers to the method of retrieve and getname() used to set the studentname. User cannot access the studentNmae directly. Hence, one has used it as a private variableand getname(), setName() in same way. According to this, user is unable to know theimplementation mechanism. Through this context it can be easily noticed the data encapsulation.Designing Strategies:Most of the people have a bitter experience of creating private class members. Thissituation occurs whenever one requires to expose them. Data encapsulation is a core part ofObject-Oriented Programming (OOP). In OOP, data encapsulation is an object design that can beattributed. It means that the hidden objects are contained with the object’s data. Class membersare restricted to use those data. It is possible to hide of data through data encapsulation. It
includes Objective-C. Therefore, it is very essential to understand the mechanism properly. Toadd new strategies in the existing class one has to add functions in it. The added new strategieswill make a category easier for further use. Just like a class description of standard Objective-c, acategory can be identified with uses of syntax, such as,@interface ClassName (CategoryName)@endThe parentheses should be mentioned with the category name.Characteristics of Category:Any classes can have a pre-declared category. In this case, it is not mandatory toimplement original source code.Original class and its subclasses will be able to use the instances of pre-declared methods.The implemented method by the category and the implemented original class does nothave any differences at the runtime.Methods:To modify the current object's state it goes through three ways:Constructor:constructor methods help to create a new instance of any object. The initialstate of the object can be set with this method. In this context, two important things mustbe noted down-First thing, every object needs not to have a constructor method in JAVA. It uses the defaultprivate values in the absence of this method.Second thing, there are differences of value in different methods. Those rely on the initialstage of the object. Therefore, numerous constructor methods can exist there at the same time.Accessor:public methods must be created by every private class in order to get back itsvalue.Mutator:whenever it is time to read the private fields instead of writing, creatingmutator is not that important.Types of Data Encapsulation:
You’re reading a preview

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document