What do lazy people want to receive?

I'm new to Grails, and I came across this name impatiently and lazily. What are they really? Would it really be nice if the answer explains when to use each of these methods?

Thanks in advance.

+4
source share
1 answer

Say you have a simple database schema with a Person table and an address table. If you are loading a person from a database, you have 2 options:

  • Download the address impatiently so that both the person and the address are returned from the database, possibly in one round trip. It loads immediately, regardless of whether it is needed or in use.
  • Download the address lazily, that is, do not download it until you need it.

This is just one example, there are many others, take this example written in C #, but should be obvious:

private ExpensiveObjectToCreate lazy; private ExpensiveObjectToCreate eager = new ExpensiveObjectToCreate(); public ExpensiveObjectToCreate Lazy { get { if(lazy == null) { lazy = new ExpensiveObjectToCreate(); } return lazy; } } public ExpensiveObjectToCreate Eager { get { return eager; } } 
+7
source

Source: https://habr.com/ru/post/1369284/


All Articles