Reconstructing heart--splitting large objects

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.