How often in your code do you see ifs checking whether the object is not null? Often? Very often? What would happen if you didn’t have to check it out? Surely code would be easier to maintain – no ifs = no test cases. This can all be achieved using Null Object pattern.
Null Object pattern should be used as a substitute for objects which don’t exists in the runtime or you don’t know current state of the object. You may apply it, however, bear in mind that it’s not suitable for all test scenarios. You’ve to analyze whether it’s a good idea to use it.
Continue reading Null Object pattern – how and when to use it
Design patterns which I would like to present in this post are well described in the book Design Patterns. Elements of Reusable Object-Oriented Software written by The Gang of Four (Gramma, Helm, Johnson, Vlissides). In my opinion this book is must read for every developer, regardless what programming language you are using. Besides the fact that this book was written more than 20 years ago, it still contains a lot of useful details for developers of all levels. I often revisit this book to keep in touch with design patterns that are detailed within. Continue reading Design Patterns – introduction