Lazy loading is a commonly used design pattern in application programming wherein we defer the creation of an object until it is actually required in an application. Proper use of the lazy load pattern can significantly improve the performance of the application.
One of the common usages of this pattern can be seen in cache aside patterns. We use the cache aside pattern for objects whose creation is expensive either in terms of resources or memory. Instead of creating them multiple times, we create objects once and cache them for future use. This pattern is possible when the initialization of an object is moved out of the constructor to the method or properties. The object will only be initialized when the method or property is called for the first time by code. It will then be cached for subsequent calls. Take a look at the following code...