Lazy loading and eager loading in the same class

I have a structure that loads many child collections from a source other than a database. I recently got a use case where the resource is on network drives and it takes the loaded collections forever. I still need to support a high load scenario, but now I need to add lazy load.

I had a solution to this bookmark but now I can't find this link. So far, Google has not returned any useful links. The first reaction is to simply add a boolean parameter to the constructor. I know this is a bad "code smell" and I remember that the answer was something else.

Can anyone point me to a resource on how to resolve this issue?

ADDITIONAL INFORMATION:

Collections are vertical, not horizontal. Therefore, background loading will not work in this particular case. This data is stored in a hierarchical structure like folders. I've seen some structures go up to 10 levels.

-1


source to share


2 answers


The solution turned out to be easier than I thought. I was just mixing modes at different levels. By that, I mean I used loading on the top-most horizontal collections and converted something else below that to lazy loading.



It works really well. Now the UI that uses this framework is very responsive.

+1


source


Yes, boolean in your constructor will definitely be bad code smell. However, I would also say that changing the class to support lazy loading is a code smell, as it violates some of the basic principles of encapsulation (i.e., does your class have to know or care if the resources are on network drives or not? ).



You shouldn't change your class. Instead, change the code that your class uses to return data on a background thread instead.

0


source







All Articles