Key Difference – DataHiding vs Encapsulation
Object-Oriented Programming (OOP)is a major paradigm in programming. It helps to develop the program or the software using objects.对象are created using a blueprint. It is called a班级。一个类由应包含在对象中的属性和行为组成。一个类包含数据成员和方法。当方法描述对象的行为时,数据成员描述对象的属性。数据隐藏和封装是OOP的两个概念。Data hiding is the process of protecting the members of the class from unauthorized access while Encapsulation is the process of wrapping the data members and methods into a single unit.This is thekey differencebetween data hiding and encapsulation. Data hiding focus on securing the data while hiding the complexity of the system. Encapsulation mainly focuses on hiding the complexity of the system. Encapsulation is a way of achieving data hiding.
内容
1.Overview and Key Difference
2.什么是数据隐藏
3.What is Encapsulation
4.Similarities Between Data Hiding and Encapsulation
5.并排比较 - 数据隐藏与表格形式的封装
6。概括
什么是数据隐藏?
The class contains data members and methods. Data hiding is the process of protecting the members of the class. Therefore, it is the mechanism to improve security. In programming languages such asJava,使用访问修饰符。他们是公共的,私人的和受保护的。公共数据成员和方法可通过其他类的对象访问。受保护的成员可以通过同一类及其子类的对象访问。私人成员可以通过类中的对象访问。
程序员可以根据应用程序使用这些访问修饰符。如果没有必要限制访问成员,他可以使用公共修饰符。Inheritance是OOP的概念。程序员可以使用已经现有的类,而不是从一开始就编写程序。现有类是superclasswhile the new class is called the subclass. The programmer can make the members of the class only accessible to that class and related subclasses using ‘protected’. If it is required to restrict accessing the data from outside the class, the modifier ‘private’ can be used.
Data hiding is to prevent other objects from accessing the members of a specific class. Therefore, the programmer should use the private access modifier. Then, the data members are only accessible through methods. If there is a class called Account and if it contains a data member as balance, that data member should not be accessible only to that class. Therefore, it can make the balance, which is a private member. Now it is only accessible within the class. This improves data security.
What is Encapsulation?
In OOP, the program or the software can be modeled using objects. Each object has attributes and behaviors. The attributes are the data members or properties and the behaviors are methods. Each object is created using a class. It provides the blueprint or a description to build objects. Encapsulation is one major pillar belongs to OOP. It is the process of combining the data members and methods into one single unit.
数据成员和方法的分组可以使程序可管理,也可以降低复杂性。矩形类可以具有数据成员,例如宽度,长度。它可以具有诸如getDetails,getarea和Display之类的方法。所有数据成员和方法都合并为称为Rectangle的单个类。在封装中,可以使用私有的,受保护的公共修饰符。访问修饰符有助于保护数据。封装可以定义为实现数据隐藏的一种方式。
What is the Similarity Between Data Hiding and Encapsulation?
- 数据隐藏和封装都是与面向对象的编程(OOP)相关的概念。
What is the Difference Between Data Hiding and Encapsulation?
数据隐藏与封装 |
|
数据隐藏是通过防止意外或预期的更改来确保对类成员和项目对象完整性的独家数据访问的过程。 | 封装是一种OOP方法,它将数据捆绑到该数据上的方法。 |
Main Focus | |
隐藏数据的重点是在隐藏复杂性的同时确保数据。 | Encapsulation focus on hiding the complexity of the system. |
Methodology | |
Data hiding is data protecting process. | Encapsulation is a method of achieving data hiding. |
访问修饰符 | |
Data hiding uses private access modifier. | 封装使用私人,受保护的公共访问修饰符。 |
概括– DataHiding vs Encapsulation
数据隐藏和封装是OOP的两个概念。Data hiding is the process of protecting the members of the class from unauthorized access. Encapsulation is the process of wrapping the data members and methods into a single unit. That is the difference between data hiding and encapsulation. Encapsulation is a way of achieving data hiding.
Reference:
1.“封装(计算机编程)。”维基百科,Wikimedia Foundation,2018年2月28日。Available here
2.“What is Data Hiding? – Definition from.”Techopedia.com.Available here
3.点,教程。“ C#封装。”,,,,Tutorials Point,,,,6 Dec. 2017.Available here
naseeb ullah说
fantastic explanation… very amazing defined data hiding and encapsulation in oop concept.