什么是封装&它是如何在我的项目中实现的 [英] What is Encapsulation & how it is implement in my project

查看:103
本文介绍了什么是封装&它是如何在我的项目中实现的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是封装以及如何在我的项目中实现

What is Encapsulation & how it is implement in my project

推荐答案

定义 - 封装意味着什么 ?/ $


在C#的上下文中,封装是指对象隐藏其用户不需要的数据和行为的能力。封装使一组属性,方法和其他成员可以被视为一个单元或对象。



以下是封装的好处:

•保护数据免受意外损坏

•指定每个成员对类外代码的可访问性

•灵活性和可扩展性代码和复杂性的降低

•降低对象之间的耦合,从而提高代码可维护性



封装用于限制对成员的访问一个类,以防止给定类的用户以设计者不想要的方式操纵对象。虽然封装隐藏了类功能的内部实现而不影响系统的整体功能,但它允许类服务于功能请求并添加或修改其内部结构(数据或方法)以适应不断变化的需求。



封装也被称为信息隐藏。



但是与抽象不同

封装和c#示例中的抽象差异 [ ^ ]



第19课:封装 [ ^ ]

什么是封装? [ ^ ]

C#中的封装 [ ^ ]



Google [ ^ ]是你最好的朋友。





希望它对你有帮助。
Definition - What does Encapsulation mean?

Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. Encapsulation enables a group of properties, methods and other members to be considered a single unit or object.

The following are the benefits of encapsulation:
•Protection of data from accidental corruption
•Specification of the accessibility of each of the members of a class to the code outside the class
•Flexibility and extensibility of the code and reduction in complexity
•Lower coupling between objects and hence improvement in code maintainability

Encapsulation is used to restrict access to the members of a class so as to prevent the user of a given class from manipulating objects in ways that are not intended by the designer. While encapsulation hides the internal implementation of the functionalities of class without affecting the overall functioning of the system, it allows the class to service a request for functionality and add or modify its internal structure (data or methods) to suit changing requirements.

Encapsulation is also known as information hiding.

but it different from Abstraction
Encapsulation and Abstraction in c# example with difference[^]

Lesson 19 : Encapsulation[^]
What is Encapsulation?[^]
Encapsulation in C#[^]
.
and Google[^] is your best friend.


Hope it helped you.


http://en.wikipedia.org/wiki/Encapsulation_(对象oriented_pr编程) [ ^ ]

http://www.c-sharpcorner.com/UploadFile/ggaganesh /EncapsulationInCS11082005064310AM/EncapsulationInCS.aspx [ ^ ]

http://msdn.microsoft.com/ en-us / library / ms173109.aspx [ ^ ]

http://msdn.microsoft.com /en-us/library/dd460654.aspx [ ^ ]
http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)[^]
http://www.c-sharpcorner.com/UploadFile/ggaganesh/EncapsulationInCS11082005064310AM/EncapsulationInCS.aspx[^]
http://msdn.microsoft.com/en-us/library/ms173109.aspx[^]
http://msdn.microsoft.com/en-us/library/dd460654.aspx[^]


公共类员工{

私有BigDecimal薪水=新BigDecimal(50000.00);



public BigDecimal getSalary(){

返回工资;

}



public static void main(){

Employee e = new Employee();

BigDecimal sal = e.getSalary();

}

}
public class Employee {
private BigDecimal salary = new BigDecimal(50000.00);

public BigDecimal getSalary() {
return salary;
}

public static void main() {
Employee e = new Employee();
BigDecimal sal = e.getSalary();
}
}


这篇关于什么是封装&它是如何在我的项目中实现的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆