Thursday, September 11, 2014

Lazy initialization Pattern

Definition

Lazy initialization Pattern is responsible to create an instance when only it is required by the Client. This is useful when the object is under creation complex and takes a lot of memory and time. Good example is a parent object that consists of lots of child objects. When the parent object is loaded, we may not want to load all the child objects at the same time. The opposite of Lazy initialization is Eager initialization.


Intention
  1. Delays the creation of an instance, the calculation of a value or some other time, memory consuming expensive process until the first time it is required.


Code

Lazy Initialization



Client

 





No comments: