Almost always you end up realizing that the software you have built required some significant change. I have been studying very deeply as to how I can minimize that additional work that I end up doing.
I have found that the best way to ensure that your code can be adapted to completely new set of requirements is by following the below mentioned rules.
1. Almost everything should be possible to to change just via configuration parameters.
2. Whatever that can not be changed/added via configuration properties alone should be changed via Inheritance
3. Whatever that can not be changed/added via inheritance must be changed via Composition
4. Only when all these attempts fail one should look at writing fresh code.
This is a very simple learning but the worst bad habit that most developers have is that of hard-coding everything. That is why we end up doing a lot of nonsensical work later.