Limit hard dependencies in your code
Written on May 17, 2012.
Igor Stasenko summarizes what he does to avoid coding with hard dependencies in his code:
Rule #1. never make more than 1 reference to any class external to your package in your code. an exception is kernel classes.
which means, that you are allowed to do
Array new, in any place of your code but never
SomeFooClass newmore than once.
If your code having such dependency, localize it in single method:fooClass ^ FooClass
and then use
self fooClasseverywhere.. Like that, if you will figure out one day, that sand moves under your feets, you’ll have to change only single method. :)
I never felt the need of doing that when the refactoring browser can rename all that for you but it’s still make sense if you want cleaner code.
Thanks Igor :)