I can’t throw glass bottles in the bin anymore. I’m not a dread-locked earth hippy but I’ve been recycling for so many years that it just feels…wrong.
Good habits work best when they’re instinctual - like muscle memory.
What if this looked weird to you?
If you’re a Rails developer this kind of thing probably litters your code but anyone with a site of significant size knows what impact this has on your tests.
1 2 3 4 5 6
Anyone else tried TDDing with a 10 minute-long test suite?
It also makes inject additional logic into process a real pain:
1 2 3
So what if you instinctually had to abstract that interface - because chaining methods just feels wrong:
You only have to test the logic within the object you’re interested in. If the connections to other objects are only one level too, simple stubbing is all you need:
1 2 3 4 5 6 7 8
Injecting logic becomes trival and remains in the right place. It also means the top-level interface to
Organisation stays untouched, regardless of what happens futher down the logic chain.
1 2 3 4 5 6
The thinking here is nothing new and is only a shallow implementation of a deeper concept, but small habits can reap big rewards as your application grows.
- Consider the entry points into the objects you create
- You shouldn’t have to poke into objects that aren’t directly connected an object
- Testing first will help with this - if you’re creating a load of objects just test one line of logic in a method - you should hear alarm bells