Refactoring: Change the code's structure without changing its external behavior
- Low coupling: Separate all that's possible to separate without making a mess
- High cohesion: Minimize the mess ~ Minimize the inter-group dependencies and maximize the intra-group ones
Invariants:
- Behavior must be the same at all times - i.e Testing
- Optionally format at all times
- Optionally 1 class per file
Procedure:
- Divide / Decompose
- Group / Abstract
- Join / Compose
-
Minimal piece of abstraction = Method
-
Group of methods = Class
-
Group of classes = Module
-
Use testing at all times
Method level:
- Extract all possible methods
- Group methods into other methods
- Compose methods
Method-Class level:
- Divide methods
- Group methods into classes
- Compose classes
Class level:
- Extract classes
- Group classes into other classes
- Compose classes
Class-Module level:
- Divide classes
- Group classes into modules
- Compose modules