Method overloads:
Method overloading refers to defining multiple methods with the same name in a class, but requiring each method to have a different number of types or parameters.
With the method overload, more can be satisfied more situations. Like what:
<span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:18PX;" > class Cat { private string name = ""; Public Cat (string name) { this.name = name; } Public Cat () //{ // this.name = "Nameless"; } public string Shout () { return "My name is" + name + "Meow"; } } </span></span>
When the cat is not overloaded without parameters, when instantiated: Cat A=new cat (); will be an error.
Method overrides:
First understand the virtual method: In order for an instance of a subclass to completely replace a class member from the parent class, the parent class must declare the member as virtual, which requires the virtual keyword to be added before the return type of the member is changed.
The child class then uses the override keyword to replace the implementation of the parent class with its own implementation.
<span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:18PX;" > class Animal {public virtual string shout ()//has virtual means that this method is a virtual method, can be overridden by the quilt class { return ""; } } </span></span>
<span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:18PX;" > class Dog:animal {public override string shout ()//method override { string result = ""; for (int i = 0; i < shoutnum; i++) result + = "Wang"; Return "My name is" +name+ "" +result; } } </span></span>
Similarly, subclasses implement the implementation of the parent class, and the method overrides and direct inheritance are different:
Inheritance is intact, all copied, unable to reflect the diversity of calls. That is, when a method for a parent class is required to be modified in a subclass, it is necessary to use a method rewrite.
Refactoring:
Refactoring (refactoring) is to improve the quality and performance of the software by adjusting the program code, making its program design pattern and architecture more reasonable, and improving the expansibility and maintainability of the software.
Software in the development process, there will be certain changes, many factors are not well found in the planning stage, only in the development process, will find some better classification methods, then should be reconstructed, so that the program is more perfect.
Overloading, rewriting, refactoring. It's easier to understand when you compare them .... These foundations should be well grasped .....
"Fundamentals of Programming"--method overloading, rewriting, refactoring