Relationship between interfaces and Classes

Source: Internet
Author: User

The reason for refactoring lies in the changes in requirements. Without changing requirements, there is no need to make a fuss about refactoring unless you are really a pain point. There are two reasons for demand changes:

I. It actually changes.

Second, we have deepened our understanding of the demand.

The old requirements are transformed into new ones, and the design is subject to changes. Of course, not all situations require major changes. Many demands do not involve "bones and muscles", so we can maintain the design skeleton and add new content. An excellent design should well predict this simple demand change.

If it is necessary to change, which designs will be easier to change? Class Design has two ideas:

First, set up operations for this Class Based on itself.

The second is to provide such operations based on requirements.

In my opinion, from the perspective of requirements, we have established a conceptual aspect, that is, an interface. From its own perspective, the specific implementation is built. When the class calls other classes, the interface is used, and when writing the class's own code, it should start from its own.

Interfaces may be smaller or larger than classes. When an interface is larger than a class, it is clear that multiple classes are required to support the complete interface. In this case, you may need to create a simple packaging class.

(When the interface is smaller than the class, it means that the system does not need more control. In this case, we should temporarily close the relevant part. If the class is regarded as a whole, the member function is a traditional subprogram concept. As an interface, member functions are part of the process .)

Interfaces are often very stable, but what changes are made when requirements change and design changes? Is the interface. Although the interface has changed, the class still exists, and because the class starts from itself, there is reason to believe that there is no need to change in front of the new interface. We can design new interfaces and use a lot of existing implementations to support new interfaces. Of course, it is inevitable to add new classes and discard many old classes, this is because the demand is changing.

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.