For example, if you want to modify the A method of a public module, and there are other modules that also use A, you can write another A1 method instead of modifying A.
Write a subclass to inherit this public method, encapsulate the parts that need to be modified into the subclass, and use this subclass for the target module.
If your modification changes the behavior of the original code, it is best to create a new one If the new code has a lot of overlap with the original code, you can consider extracting the reusable parts
Abstract it
Then write multiple methods to implement the abstract method, and different functional points implement different business logic.
The easiest way. Copy it and quote it separately.
For example, if you want to modify the A method of a public module, and there are other modules that also use A, you can write another A1 method instead of modifying A.
You can overwrite the public part of the code of the subclass, and you can modify the function of one of them at will
Create a category Override this method in the category Import the category in this file.
Write a subclass to inherit this public method, encapsulate the parts that need to be modified into the subclass, and use this subclass for the target module.
Create a new method. A way to package others.
If your modification changes the behavior of the original code, it is best to create a new one
If the new code has a lot of overlap with the original code, you can consider extracting the reusable parts
Two ways:
Add flag type parameters to the method, and perform different processing according to different flags in the method
Rewrite one more method
Let’s modify that method by classifying it