Ask a question from expert

Ask now

Concept of Data Encapsulation

10 Pages2878 Words302 Views
   

Added on  2019-09-26

Concept of Data Encapsulation

   Added on 2019-09-26

BookmarkShareRelated Documents
Data EncapsulationNowadays it is a very important concept to hide confidential data from a hacker or such cyber 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 in recent years. Everyone can use the implantation details without any side effects. Encapsulated code gives the power to everyone.About Data Encapsulation:Object-Oriented Programming is a model for programming languages where programs are written by organizing it into objects and data instead of functions. Object-Oriented Programming has some properties like Encapsulation, Abstraction, Inheritance, and Polymorphism. The mechanism of hiding implemented details, as well as functions, is called encapsulation.In the implementation level, the code and data are wrapped up with a single unit. Data encapsulation is used to set a restricted layer of functions. A user cannot operate the restricted set. Data is kept inside a class. Each object state and implementation are kept inside any class privately. Other objects cannot make any change for private methods. Only public methods can be 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 should keep in mind the matter about flexibility or restrictiveness for hiding data. Therefore, the integrity of data is guaranteed with encapsulation. The private fields as well as the public behaviour toward class help to achieve the goal.Example-public class Student{private string studentName;public string getname(){return studentName;
Concept of Data Encapsulation_1
}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. This situation occurs whenever one requires to expose them. Data encapsulation is a core part of Object-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 members are restricted to use those data. It is possible to hide of data through data encapsulation. It
Concept of Data Encapsulation_2
includes Objective-C. Therefore, it is very essential to understand the mechanism properly. To add new strategies in the existing class one has to add functions in it. The added new strategies will 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 to implement 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 not have 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 must be 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 initial stage 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 its value.Mutator: whenever it is time to read the private fields instead of writing, creating mutator is not that important.Types of Data Encapsulation:
Concept of Data Encapsulation_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Object-Oriented Design Choices in Future College Console Program
|13
|1508
|247

Object Oriented Programming: Inheritance, Encapsulation, Polymorphism
|11
|1451
|340

Blog on Data Encapsulation
|3
|555
|285

Report on Enterprise Software Development
|14
|2362
|90

Blog: Data Encapsulation
|8
|2755
|200

OO Basics and Smalltalk: A Beginner's Guide to Object Oriented Programming
|5
|702
|168