Large Object Evolution process:
In many legacy systems, when we break down thousands of of rows of large functions into dozens of small functions, there is another problem, that is, these small functions are cluttered in the class, making this class A super class with all-encompassing functions, extreme coupling, and the possibility of stepping on a hole with minor modifications and introducing bugs.
Large Object Splitting method
The way to split large objects is to "Extract the class": The process is very simple, which is to move some of the methods in the original object to other "suitable" objects (new or existing) to build a software system with high-cohesion coupling.
Large object Split principle 1, driven by responsibility split
The so-called responsibility-driven, that is, we design the class and interface must be around "a specific responsibility" to do, class and interface functions are highly correlated (high cohesion).
2. Create objects based on domain model
This paper analyzes the domain model, analyzes the related things in the domain model, the properties of things, the behavior of things and the relationship between things, then combs the corresponding objects in the software system, creates the objects according to the domain model, and encapsulates the function functions in the respective business classes respectively.
3. Information experts
An "information expert" is a business object that has some useful data in a software system, and we should assign a method to the information expert who has the data needed to execute the method. For example, the function needs to be the name of the commodity, then to the commodity business class, the function is required is inventory information, the distribution to the inventory management business class.
4. Single duty
When splitting large objects, be sure to follow a single principle of responsibility. A duty is a reason for software change, "responsibility" of the granularity must not be too large, otherwise the responsibility will contain a lot of small responsibilities, virtually introduce a number of changes, to the risk of refactoring.
Notes
Extraction class Tips
Same code: You can extract a parent class to inherit from the business subclass
Different code: In the business classes that belong to their respective responsibilities
Different implementations of code: You can use abstract methods and interfaces to implement
Reconstructing heart--splitting large objects