On 05/29/2018 08:49 AM, sergio ruiz wrote:
If a model has a list of things.. such as a user that can/may have lots of pets, are there any real benefits to initializing the list of pets lazily?

Yes, there's a huge benefit to lazy initialization; it's more resilient to class changes in the face of deserilization of old class shapes. If you add new instance vars to a class, and then deserialize older version those instance variables will be nil. With lazy init, this is not a problem. Without lazy init, this is a null ref exception.

These old versions could be from a cache of data from the previous version of the code. It's no fun to have to lose all cache data just because you push out a new version of the code.

In of the face of persistence, i.e. serialized versions of your objects, lazy init is the way to go.

--
Ramon Leon


Reply via email to