Object-oriented basic advanced 02 and object-oriented advanced 02

Source: Internet
Author: User

Object-oriented basic advanced 02 and object-oriented advanced 02

I. Three features of object-oriented

Encapsulation, inheritance, and Polymorphism

Encapsulation

1: Concepts and functions of encapsulation

* The private and public modifiers are used to modify the class members (fields, attributes, methods, and so on) so that private data and methods are not accessed by the outside world. This feature is encapsulation;

* An attribute, a method is encapsulation, and a class is encapsulation of attributes and methods;

* Encapsulation is an important feature of object-oriented systems. Three Important features of object-oriented systems are encapsulation, inheritance, and polymorphism;

* Function <modularization and Data Hiding>

2: The class is a template, and the identified object will have the features (attributes) and behavior (methods); any object will belong to a class;

3: An object is created as a template, and is instantiated and embodied in a class;

4: benefits of object-oriented

* Encapsulation allows developers to pay more attention to their needs;

* A class can be used multiple times after definition to avoid repeated value assignment;

5: The class tries to display the overall structure of the class; the class (right-click to view the class diagram)

6: Class ancestor (object)

* The Object class is the parent class (ancestor class) of all classes. Therefore, any class can be converted to the object type;

* Values of any type can be assigned to variables of the object type;

Packing: the process of converting a value type variable to a <object> object is called packing;

Unpacking: the process of converting <object> object type variables into value types is called unpacking;

Class A {public virtual void F () {}} class B: A {public override void F (){}}

Polymorphism <polymorphism during compilation and Runtime polymorphism>

* Like the definition of overload, it can be said that overload is also a type of polymorphism.

* Class inheritance occurs between multiple classes, while class polymorphism occurs on the same class. In a class, multiple methods with the same name can be defined, you only need to determine the number and type of their parameters.

Understanding the following section shows the polymorphism.

Foreach (Student stu in students) {Console. writeline (stu. studentName );}

2: Maximum features of a generic set: strictly constrain the element types in the Set;

3: Set Initiator

Initialize the set object directly when creating it, which is very similar to array;

4: Dictionary <k, v> is generally called a Dictionary.

* <K, v> constrain element types in the Set

* Check the type constraints during compilation;

* Binning is not required.

* Operations related to hash tables

 

Related Article

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.