In this chapter, I have explored four basic creational patterns.
The first one was singleton, a pattern used when we need exactly one instance of a class. The chapter looked at a few bad and a few good implementations and explored alternatives.
After that, I switched to the DI pattern, which can sometimes be used to replace a singleton. As DI is incredibly large area, the chapter has focused on basics and explored different injection mechanisms.
The third pattern in this chapter was lazy initialization. The mechanism behind the lazy initialization (the test, create, use idiom) is so simple that most of the time we don't think about this concept as a pattern. It can still be tricky to implement this pattern correctly, and I have pointed to few potential problems and offered a way to overcome them.
For the last pattern in this chapter, I have looked into the object pool. This pattern is used when creating and initializing new object is a costly operation. The object pool represents a storage...