All code can be classified into two distinct roles; code that does work (algorithms) and code that coordinates work (coordinators).
The real complexity that gets introduced into a code bases is usually directly related to the creation of classes that group together both of these roles under one roof.
Computer electronics have two roles: doing work and binding together the stuff that does the work. If you take out the CPU, the memory and all the other components that actually do some sort of work, you’ll be left with coordinators. Wires and busses that bind together the components in the system.
So now that we understand that code could potentially be divided into two broad categories, the next question of course is why? And can we even do it?
Let’s address why first.
The biggest benefit to pulling algorithmic code into separate classes from any coordinating code is that it allows the algorithmic code to be free of dependencies. (Practically all dependencies.)
Once you free this algorithmic code of dependencies you’ll find 3 things immediately happen to that code:
- It becomes easier to unit test
- It becomes more reusable
- Its complexity is reduced