C # encapsulation of three object-oriented features

Source: Internet
Author: User

I have always been vague about the concept of encapsulation. What is encapsulation?

In fact, encapsulation is everywhere when we write code.

First, classes and objects are the embodiment of encapsulation. Encapsulate the common features of some column objects as a class, and encapsulate the features of a specific thing as an object.

In addition, the following are encapsulation:

1. Attribute encapsulation of fields

2. encapsulate multiple parameters of a method into an object

3. Put a bunch of code with a specific function into a method,

4. encapsulate some common types or methods into a set of programs.

What are the advantages of encapsulation?

I have summarized the following points:

1. Code can be reused. Write frequently used functions into a method.

2. The caller does not have to worry about the specific internal implementation. Through the released interface, the caller can simply implement the call (and also hide the technical details ).

3. Security verification can be performed. If you do not want to assign values directly to a value of an object, you can encapsulate it and perform security verification internally.

OK. This is the encapsulation first.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.