Bad taste of code [3]

Source: Internet
Author: User

Bad taste of code [3]

Total returned directory

9. Primitive Obsession (basic type paranoid)

This is mainly manifested in the excessive use of basic types.

1. A basic type field that is always put together can be extracted from a class.

2. There is basic type data in the parameter column, which is the same as the eighth "Bad taste" and can be extracted into objects.

3. If you are selecting data from an array, replace the array with an object.

10. Switch Statements)

One of the most obvious characteristics of object-oriented is that the switch... case... statement is rarely used. Essentially, the problem with switch statements lies in repetition. You often find that the same switch statement is distributed in different locations.

1. If the switch statement is selected based on the type code, the polymorphism is considered.

2. If there are some selection cases in a single function, you can replace the parameter with a specific function.

11. Parallel Inheritance Hierarchies (Parallel Inheritance system)

There are two bad tastes:

1. When adding a subclass to a class, you must add a subclass to another class.

2. the prefix of an inherited system class name is the same as that of another inherited system class name.

Eliminate this repetitive strategy: an instance in one inheritance system references an instance in another inheritance system, and then migrates the Member

12. Lazy Class (redundant Class)

In fact, a class does not do so much work or has nothing to do.

1. If there is no big difference between the parent class and the Child class, combine them into one.

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

13. Speculative Generality)

1. Try to handle unnecessary things with various hooks and special circumstances.

  • An abstract class does not have much function. It combines Parent and Child classes.
  • Unnecessary delegate, move all the features of this class to another class, and then remove the original class.
  • Some parameters of the function are not used. Remove the parameters.
  • The function name has a redundant abstraction meaning. Rename the function name.

2. The only user of a function or class is a test case.

In this case, delete such functions or classes together with test cases.

 

 To Be Continued...

Related Article

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.