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