Singleton Design Pattern

Design patterns are important as they help us solve general problems with software that people face during development. These patterns help us make code maintainable, extensible, and loosely coupled. One such design pattern is the Singleton Design pattern.

In simple terms, Singleton is a class that allows us only to create a single instance of it. It makes it impossible for us to instantiate the class for the second time.

How to Unit Test Classes Which Create New Objects

Learn how to conduct effective unit tests.

First of all, I will start with a disclaimer that I am a strong proponent of using the simple factory programming idiom and by extension of using the Factory Method Pattern, instead of creating objects inside classes. The factory idiom helps you to insulate your code to changes thereby adhering to the Open to Extension Close to modification principle of object-oriented programming.

You may also like: Unit Testing: The Good, Bad, and Ugly

Also, the idea is to write testable code, not to write a hack to test code.