Common methods of removing redundant code scored by
- Ease of Implementation (lower is more difficult)
- Dont Repeat Yourself (lower involves more repetition and therefore more prone to bugs)
- Loose Coupling (lower involves higher degrees of coupling and therefore more prone to bugs)
Ease | DRY | Loose Coupling | Refactoring Method |
---|---|---|---|
5 | 1 | 5 | Copy paste |
4 | 4 | 2 | Extract static method |
3 | 4 | 2 | Extract extension method |
3 | 4 | 3 | Extract base class |
-5 | 5 | 4 | Aspects* |
4 | 4 | 2 | Extract public method |
4 | 4 | 3 | Extract private method |
3 | 4 | 4 | Extract method with lambdas as parameters |
3 | 3 | 3 | Extract service/helper class (locally newing up instance) |
2 | 3 | 4 | Extract service/helper class (injecting dependencies) |
? | ? | ? | Precompiler macros |
? | ? | ? | LISP-style macros |
? | ? | ? | Mixins ** |
? | ? | ? | Extend |
? | ? | ? | Dynamic metaprogramming |
* Ease of Aspects greatly depends on your language and development toolstack. This chart assumes a standard C# stack not using any particular aspect framework.