First, let's look at a SE engineer class:
//<summary>// Engineer Class ///</summary>
Public classSE {/// <summary> ///Work No./// </summary> Public stringID {Get;Set; } /// <summary> ///Age/// </summary> Public intAge {Get;Set; } /// <summary> ///name/// </summary> Public stringName {Get;Set; } /// <summary> ///Sex/// </summary> PublicGender Gender {Get;Set; }}
Look again PM Project Manager class:
// <summary>
Project Manager class
</summary>
Public classPM {/// <summary> ///Work No./// </summary> Public stringID {Get;Set; } /// <summary> ///Age/// </summary> Public intAge {Get;Set; } /// <summary> ///name/// </summary> Public stringName {Get;Set; } /// <summary> ///Sex/// </summary> PublicGender Gender {Get;Set; }}
Among the two classes, there are many identical fields.
In order to reduce the code, I can put the same code in a public employee class employee
/// <summary> ///Employee Class/// </summary> Public classEmployee {/// <summary> ///Work No./// </summary> Public stringID {Get;Set; } /// <summary> ///Age/// </summary> Public intAge {Get;Set; } /// <summary> ///name/// </summary> Public stringName {Get;Set; } /// <summary> ///Sex/// </summary> PublicGender Gender {Get;Set; }}
Then we say that the SE class and the PM class are subclasses, and the employee class is our parent class, and the subclass only needs to inherit the parent class, so we don't have to define the parent class properties.
This allows you to reduce the code and clarify the role of the program structure.
For example:
Public class Se:employee {}publicclass pm:employee {}
: number, which means inheritance.
We can summarize.
Inheritance is an object-oriented feature that can help us remove redundant code from a class.
Inheritance in C #