I just had a moment of clarity about refactoring and encapsulation. Its a simple truth and is one of the basic tenants of the concept and I had kind of forgotten about it.
It occured to me because I was working with some javascript. Its very easy to end up with lots of global methods in JS unless you use your closures properly.
By putting variables inside functions you can make them private.
Why is this useful. Well consider that you want to CHANGE one of those functions. Change ? who would EVER want to do that ?
If it is declared as a private function you KNOW FOR SURE that no-one else is using it and therefore that YOU CANNOT BREAK ANY OTHER CLASSES.
Therefore it is COMPLETELY SAFE TO REFACTOR.
great isnt it!
Such a thing you take for granted and yet when you work with a different language domain it suddenly reminds you of all the good things about OO.
non-random ramble :: “Object Calisthenics” : Jeff Bay | 04-Mar-09 at 12:05 pm | Permalink
[...] I also liked the fact that eight out of the ten rules were all about encapsulation something I have also been thinking a good deal about recently, prompted by this experience, even to the extent of even getting it printed on a t-shirt (but that’s another story). [...]