Basketball in basketball

xiaoxiao2021-03-06  20

Basketball in basketball

= Initialization problem =

Of course, I have to warm up before the start of the half, I'm going to have an exciption - twisted feet, I still hurt the feet, 555 ...

Solution: Don't speak clear.

Note: To avoid no initialization, often accompany a large number of IF (xx == null), this problem is mainly to see NULL misses the default value of the object. A skill to solve this problem is to introduce a "nullobject" as its default value, that is, the call to the invocation of the initialized object is converted to this "nullobject" default object method, which eliminates these redundant IFs ( XX == NULL).

= Long method =

Brush brush, a series of movements, handsome stay (of course, it is said).

"How to do it, teach your younger brother."

"Ok. Look, the first move, come over, then then, then ..."

"@ #% * ..."

It's really stupid, taught tens of times, he still didn't learn ...

"This way, change a teaching method, decompose action, first come to Crossover, and then ..."

It's so smart, I learned in two or three!!!

"It turned out to be so simple, it will, why isn't it?"

"Who told you not to ask!" (Seems to have an answer)

Solution: Plus a comment in this method body, and then put each comment block as a method, it is as simple as it is.

Note: Large Class et al. Also uses a similar practice.

= Long parameter list =

For writing an article about basketball (enough boring). Some data is required, such as the quality, volume, and elastic coefficient of basketball. You don't have to tell you after one by one, just put a basketball to you, these data will naturally get it.

SOLUTION: If these parameters are combined, it makes sense, introducing an object, allowing it to hold these parameters, and then make this object becomes the parameters of this method, and modifications to this method.

Note: The coupling between the class may increase.

= Primitive obsession =

Among the NBA, a team has an attribute to express a record. At first, for simplicity, it may be represented by a String object, such as "12: 7". But if you need to make it a win rate, rankings, etc. The solution is to design a record of record, so that it holds, negative, winning, ranking, etc., which is clear.

Solution: Change those primitive or near-primitive Types to meaningful objects.

Note: Object-oriented is to object-oriented.

= Feature envy =

I have a lot of killing skills, some of which have a skill, listening, that is called Xiao Wang's first Crossover, change again, and stop ... Hey, how is the little king? Hey, this must kill the skills, give Xiao Wang calculate.

Solution: If a method always calls the method of another object, move the method to the corresponding object.

Note: Sometimes this situation is reasonable, such as strategy mode and visitor mode.

= DIVERGENT CHANGE =

One game, I am a referee, whistling, score, and I have a person. In the half, because I'm going back, I've been tired of adult, but I ble a lot of "black whistle" because I am busy. So, I found two people, and one person remembered, another person and half a field. Oh, I really have a pleasant in the second half, and there is almost no misunderstanding, but the salary has dropped half ... Solution: If there is a variety of reasons, it will make an object change, indicating that there are too many responsibilities (three minus.) . This object can be decomposed into multiple objects by demand.

Note: a Module Should Have ONLY One Secret.

= Shotgun Surgery =

This competition, 俺 and the little king are the maintor, two borders, no mistakes, don't worry, there is more free, that is, the whistle, Xiao Wang is responsible for the rule of the rule, creative! However, the division of labor seems to be too "clear". Ha ha.

Solution: If a simple change involves a few objects, that is, the responsibility of a matter is scattered into several objects. At this time, what you have to do is to extract this whole thing from these objects, then Other objects make corresponding adjustments, which may make several objects into one object.

Note: Of course, there are special examples, such as models and views in the observer mode, because views and models usually require alone.

Reference book << Refactoring Workbook >>

<< Refactoring >>

If you are inappropriate, please point out.

转载请注明原文地址:https://www.9cbs.com/read-49131.html

New Post(0)