In computer programming, lazy initialization is the tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.
This is typically accomplished by maintaining a flag indicating whether the process has taken place. Each time the desired object is summoned, the flag is tested. If it is ready, it is returned. If not, it is initialized on the spot.
storing the instances in a map, so you get the same instance the next time you ask for an instance with same parameter (compare with a singleton pattern)
using lazy initialization to instantiate the object the first time it is requested (lazy initialization pattern).
Here is a dummy example (in Java). The Fruit class itself doesn't do anything here, this is just an example to show the architecture. The class variable types is a map used to store Fruit instances by type.
The following is an example (in Smalltalk) of a typical accessor method to return the value of a variable using lazy initialization.
The 'non-lazy' alternative is to use an initialization method that is run when the object is created and then use a simpler accessor method to fetch the value.