| Conditions | 11 |
| Total Lines | 56 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 11 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like fr.quatrevieux.araknemu.game.listener.player.inventory.SendWeight.listeners() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /* |
||
| 42 | @Override |
||
| 43 | public Listener[] listeners() { |
||
| 44 | 1 | return new Listener[] { |
|
| 45 | 1 | new Listener<GameJoined>() { |
|
| 46 | @Override |
||
| 47 | public void on(GameJoined event) { |
||
| 48 | 1 | send(); |
|
| 49 | 1 | } |
|
| 50 | |||
| 51 | @Override |
||
| 52 | public Class<GameJoined> event() { |
||
| 53 | 1 | return GameJoined.class; |
|
| 54 | } |
||
| 55 | }, |
||
| 56 | 1 | new Listener<CharacteristicsChanged>() { |
|
| 57 | @Override |
||
| 58 | public void on(CharacteristicsChanged event) { |
||
| 59 | 1 | send(); |
|
| 60 | 1 | } |
|
| 61 | |||
| 62 | @Override |
||
| 63 | public Class<CharacteristicsChanged> event() { |
||
| 64 | 1 | return CharacteristicsChanged.class; |
|
| 65 | } |
||
| 66 | }, |
||
| 67 | 1 | new Listener<ObjectQuantityChanged>() { |
|
| 68 | @Override |
||
| 69 | public void on(ObjectQuantityChanged event) { |
||
| 70 | 1 | send(); |
|
| 71 | 1 | } |
|
| 72 | |||
| 73 | @Override |
||
| 74 | public Class<ObjectQuantityChanged> event() { |
||
| 75 | 1 | return ObjectQuantityChanged.class; |
|
| 76 | } |
||
| 77 | }, |
||
| 78 | 1 | new Listener<ObjectAdded>() { |
|
| 79 | @Override |
||
| 80 | public void on(ObjectAdded event) { |
||
| 81 | 1 | send(); |
|
| 82 | 1 | } |
|
| 83 | |||
| 84 | @Override |
||
| 85 | public Class<ObjectAdded> event() { |
||
| 86 | 1 | return ObjectAdded.class; |
|
| 87 | } |
||
| 88 | }, |
||
| 89 | 1 | new Listener<ObjectDeleted>() { |
|
| 90 | @Override |
||
| 91 | public void on(ObjectDeleted event) { |
||
| 92 | 1 | send(); |
|
| 93 | 1 | } |
|
| 94 | |||
| 95 | @Override |
||
| 96 | public Class<ObjectDeleted> event() { |
||
| 97 | 1 | return ObjectDeleted.class; |
|
| 98 | } |
||
| 108 |