Lazy Load Pattern


Definition
Lazy loading is a software design pattern where the initialization of an object occurs only when it is actually needed and not before to preserve simplicity of usage and improve performance. In another word "Lazy initialization of an object means that its creation is deferred until it is first used."

Applicability
  • When you have an object that is expensive to create, and the program might not use it.
  • When you have an object that is expensive to create, and you want to defer its creation until after other expensive operations have been completed.

Consequences
  • Prevent system memory or computing cycles usage when there is no reason to do it.
  • Improve the startup performance of the program

Downsides
  • When initializing there can be some lag when things are getting loaded into memory.
Sample Code
The following code snippet demonstrates how lazy loading works:


Comments

Popular Posts