Refactoring Method 13: inline class (associating classes)

Source: Internet
Author: User

 

A class does not do much.Move all features of this class to another class, and then remove the original class..

Motivation: The Inline class is the opposite of the extract class. If a class no longer bears sufficient responsibilities and has no reason to exist independently (this is usually because the previous refactoring action removes the responsibility of this class ), select the most frequent user (also a class) of this "shrinking class", and insert the "shrinking class" into another class by using the inline class method.

Practice: 1. Declare the public protocol of the source class on the target class and delegate all functions to the source class. If "using an independent interface to represent source class functions" is more appropriate, you should first use extract interface (extract Interface) before inline)

2Modify all source class reference points and reference the target class. Declare the source class as private to cut off all references outside the package. Modify the name of the source class at the same time, which enables the compiler to help you capture all hidden reference points of the source class.

3, Compilation, and testing.

4Use the move method and move field to move all features of the source class to the target class.

5, Delete the source class.

 

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.