The design tends to be complicated.

Source: Internet
Author: User

Related content: object-oriented ideas brainstorming (1)

AssociatedArticleA specific case of the open and closed principle was discussed. The first two of them are super complicated designs and completely do not comply with the open and closed principle. However, I think if I have never learned the so-called design patterns, I will never make the first two mistakes of "over-pattern. Therefore, the fans of design patterns should be careful to let youCodeWhat gets disgusting is often what you are keen on.

Then, use the third delegate.

The fourth method is the combination interface.

Maybe the example is not good enough. I think the third and fourth are not perfect.

Let's review the design requirements:"

Three types of books need to be processed, such as digital and consumption. The tax rate of products needs to be calculated. The tax rate of books is 0.1 of the price, and that of digital and consumer products is 0.11 of the price. Information about the three types of products needs to be obtained, the information of books and consumer products is: "name:" + name;. The information of digital products is: "Digital name:" + name;

"

There is a product category, and then let you join the tax rate and print the problem, what do you do?

You can select the appropriate policy for each product, as shown in the design adopted by the associated articles.

Product A. Tax Rate = Policy 1.

Product B. Tax Rate = Policy 2.

However:

Product c. Tax Rate = Policy 1.

Product D. Tax Rate = Policy 2.

......

You may need to produce one thousand different products, but find that both strategies come and go.

My analysis is like this. First of all, there is a product class. Now we need to add and print. According to the requirements, policies depend not on specific products, but on the product type. Therefore, I think we should first increase the abstraction to the previous level and program the types of different products.

Digital category {tax rate}

Product Category {type A; Price B; Name C;

Total price: A. Tax Rate * B;

Print: A. Print (c)

}

Product Type: computer. A = digital.

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.