June 2003
Intermediate to advanced
800 pages
34h 20m
English
You have an object that contains data that’s expensive to create and might not be required.
Use the lazy initialization pattern to create or to retrieve the information "just in time."
The lazy initialization pattern is often used with stateful objects that need to retrieve data from a database, but it can be applied to any object that’s expensive to create. The basic approach is to use a Boolean private member variable IsInitialized to track whether the object data has been retrieved yet. Here’s a basic skeleton that illustrates the concept by setting a string variable:
Public Class MyObject Private IsInitialized As Boolean = False Private _Data As String Public ReadOnly Property Data() ...
Read now
Unlock full access