Class Invariants

Recently I came across a class used to store some application configuration. The configuration was stored in an XML file which was parsed in the constructor of the class. Each method of the class started with getting the root element of the XML file and if that element did not exist it needed to be created. That was a lot of code repetition that could be extracted into a common private method. But before I started changing the code, I realized it could be done in a more elegant way. Read the rest of this entry »