Michael Knopf

turning concepts into working products...

Basics of Lazy Loading
Michael Knopf
Monday, July 21, 2008 | Share on Facebook RSS Feeds

Lazy Loading is the idea of providing an objects related information only when you actually need it, instantiating related objects and populating its properties when its first requested and not before. This reduces the amount of processing power required by giving you what you ask for in smaller bites (or should i say Bytes)

There are 4 ways lazy loading can be implemented

Lazy Initialization: The object to be lazily loaded is initially set to NULL, and every request for the object checks for NULL and creates it “on the fly” before returning it first

Virtual Proxy: a virtual proxy is an object that “looks like” the object that is to be lazily loaded. Both the object and the proxy implement the same interface, with the proxy providing a wrapper that instantiates and initializes the object when one of its properties is accessed for the first time

Ghost: a ghost is the object that is to be loaded in a partial state. It may only contain the objects identifier, but it loads its own data the first time one of its properties is accessed.

Value Holder: a value holder is a generic object that handles the lazy loading behavior, and appears in place of the object’s data fields.

Most Object Relational Mapping system take advantage or Lazy Loading, which is an added benefit and one more incentive to using ORM software factory systems.