Lazy loading in Container Designs

Lazy Loading in Container Designs

There are other applications of virtual proxies as well. “Lazy Loading” used in component container architecture model and container designs is a classical example of the same.

As we know most of our component based models and containers are object relational ie although within containers we deal with objects but still our data gets persisted in a relational database ie every class has a associated table, the rows of the table is represented by every object while the column names of the tables are the attributes of a class. Now lets say we fired a query in the database which is supposed to return 2000 records each having 20 columns each ie 2000 objects should be created in the container each having 20 attributes. Now ask yourself is it a prudent design decision to create 2000 heavy weight objects in memory when there is no guarantee that the user wants to access all the records of the table. It might just be possible that a user might want to access only 10 records of the 2000 records.

Figure- Figure

The answer to this is when the database returns 2000 records, instead of creating 2000 actual objects in the container, the container only creates 2000 virtual proxies for every record and user is returned a reference to these virtual proxies.

Figure- Figure

Only when the user wants to access a particular record, the virtual proxy will load the actual object in memory by firing a call on the database and loading the relevant details.

Figure- Figure

Virtual proxies are extensively used in designing containers.

Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer