1. Principle of encapsulating objects
Encapsulation is to hide the internal class. Advantages: 1. Good encapsulation can reduce coupling, 2 internal implementations can be freely modified, and 3 have clear external interfaces.
2 Inheritance
How to access base class members
The derived class can call the method of the base class. Through the base keyword, the derived class has some restrictions when accessing the base class. Private Members cannot be accessed. The base class members of interal can only be accessed by the derived classes in the same assembly. If the class child inherits the class parent, the child object contains a parent object.
3 polymorphism
Polymorphism requires a derived class to rewrite virtual functions in the base class. virtual functions are also called virtual functions. The virtual keyword Public Virtual bool withdraw (...) is used (....) {..}, when a virtual method is called, The runtime determines the class instance when the object is called, and calls an appropriate rewrite method.
Rewrite method: 3 Requirements: Same method name, same parameter list, same return value
Overload method 3 Requirements: the same method name, different parameter lists (type and quantity), can return different values
Abstract Method: A derived class must implement all abstract methods in the base class (the abstract method does not have a method body). If the class contains abstract methods, the class must be declared as an abstract class.
When to use inheritance
Code reuse to reduce coding workload
Design reuse: common fields and methods can be placed in the parent class, and then a new subclass is derived from it. The subclass has its own fields and methods.
Class Structure in. net
4 Interface
The interface provides a blueprint for the class
The interface only provides definitions
The data type of the implemented interface must be implemented by interface members.
The interface itself can be derived from multiple basic interfaces