A few months ago I posted about my thoughts on Object Construction (found here). In the post I talk about constructing object with ALL the required values to make the object valid.
This post is just a quick follow up to that. The other day I was refactoring some code and needed to add a new property to it. The new property was a required one and the object would not be considered valid without it being populated. Because I have my constructor require all needed properties, I simply added the parameter to the constructor's signature and re-compiled.
Because this is now part of my constructor I instantly knew where I needed to update my code to add this call (yes I know I could have found this other ways, but this is the simplest if you ask me). Had my constructor NOT required the values, I would have had to search for every use of the object and perform a set on my new property. This is doable, but is more error prone. With my luck I would have missed something.
Anyway, the point of this was that if you put requirements on your objects it will make for simpler and easier refactoring later.
Till next time,