Thursday, September 2, 2010

Java development of the 21 most easily commit errors

1.Duplicated Code code duplication almost smell the most common. He is also one of the main objectives Refactoring. Repeat the code often comes from the copy-and-paste style of programming. And his relative is a good system should be OAOO important symbol. 2.Long method is the traditional structure of the "residual poison." A method should have an independent means of self ...

1.Duplicated Code
Code duplication almost smell the most common. He is also one of the main objectives Refactoring. Repeat the code often comes from the copy-and-paste style of programming. And his relative is a good system should be OAOO important symbol.


2.Long method

It is the traditional structure of the "residual poison." A method should have the intention of self-independence, not to put together a few intent.

3.Large Class

Categories is that you put too much responsibility to a class. Here the rule is One Class One Responsibility.

4.Divergent Change

The contents of a class rate of change inside different. Change once an hour in some states, some are only changed once a year a few months; some of the state because of the reasons for this change, while others change because of other causes first. Object-oriented abstraction is relatively constant and the relative changes in relative isolation. To change the one hand and on the other hand the problem isolated. This makes them relatively constant can be reused. Changes in every aspect of the problem can be reused individually. This change in the coexistence of different makes reuse difficult.

5.Shotgun Surgery

This is just above the opposite. A place to change the system involves many other areas related to change. These changes and change the status and behavior of similar content should be placed generally in the same class.

6.Feature Envy

The purpose of the object is encapsulated, and the closely related with the behavior of these states. If a class method frequently used method of access to get the status of other types of calculations, you should consider actions involving the state moved to the largest number of that class.

7.Data Clumps

Some data usually play in groups like children: with the members of the class in a lot of variables, together with the parameters in many ways, these data should perhaps form their own independent object.

8.Primitive Obsession

Object-oriented newcomers often accustomed to using several types of data to represent the original concept. For example, the scope, they will use two figures. For the Money, they would use a float to represent. Because you do not use objects to express the problems that exist in the concept, which makes the code becomes difficult to understand, difficult to solve problems increased significantly. Good habit is to expand the original language can provide the type of object used to represent the range of small, amount, conversion rate, zip code and so on.

9.Switch Statement

The switch statement is based on the constant enemy of OO, you should put him into a sub-class, state, or strategy.

10. Parallel Inheritance Hierarchies

Parallel inheritance hierarchy is the special situation of shotgun surgery. Because when you change a level in one class, you must also change the level of parallel another subclass.

11. Lazy Class

A small working class. Class maintenance requires additional overhead, if a little class to bear the responsibility should be to eliminate it.

12. Speculative Generality

Never use a class implements the functionality and versatility. Usually the only such class or method the user is testcase. Do not hesitate to delete it.

13. Temporary Field

The properties of an object may only be meaningful in some cases. This code will be difficult to understand. Specifically to hold such an object property of orphans, the only relevant conduct and his move to the class. The most common is a specific algorithm needs only the algorithm have to use some of the variables.

14. Message Chain

Message chain occurs when a client requests to an object to another object, and then another object that demands our customers Youxiang another object, again requested that another object to another object, such and such. At this point, you need to hide the distribution.

15. Middle Man

One of the basic characteristics of the object package, and you are often assigned to achieve through the packaging. But this step can not go too far, if you find one half of a class interface methods are assigned to do, you may need to remove the middleman.

16. Inappropriate Intimacy

Some classes are too close to each other, they spent too much time to research other people's private part of the brick. For humans, we may not be too prudish, but we should make their own class of strict compliance with asceticism.

17. Alternative Classes with Different Interfaces

Method of doing the same things have different function signature, consistent with them to move up the class hierarchy until the agreement unanimously.

18. Incomplete Library Class

To create a good class library is very difficult. We work a lot of procedures are based on class library. However, such extensive and disparate objectives of the library building were put forward harsh requirements. Library builder is not omnipotent. Sometimes we find that library class can not be achieved we need to functionality. The changes directly to the library classes are very difficult. This time you need to use a variety of means Refactoring.

19. Data Class

Objects, including state and behavior. If a class is not only the state act, then certainly something had gone wrong.

20. Refused Bequest

Superclass inherited a lot of behavior and state, but only with a subclass of which very little. This usually means a problem with your class hierarchy.

21. Comments

Often feel that a lot of comments that you write the code difficult to understand. If this feels too much, that you need to Refactoring.

No comments:

Post a Comment