Skip to main content

Questions tagged [lazy-initialization]

37votes
6answers
22kviews

Why isn't lazy evaluation used everywhere?

I've just learnt how lazy evaluation works and I was wondering: why isn't lazy evaluation applied in every software currently produced? Why still using eager evaluation?
John Smith's user avatar
21votes
6answers
18kviews

DDD Injecting Services on Entity Methods Calls

Short format of question Is it within best practices of DDD and OOP to inject services on entity method calls? Long format example Let's say we have the classic Order-LineItems case in DDD, where ...
e_i_pi's user avatar
10votes
4answers
2kviews

Is there any reason lazy initialization couldn't be built into Java?

Since I'm working on a server with absolutely no non-persisted state for users, every User-related object we have is rolled out on every request. Consequently I often find myself doing lazy ...
Nicole's user avatar
  • 28.2k
8votes
1answer
1kviews

Is there a name for the counterpart of the lazy loading pattern?

Definition of the lazy loading pattern from Wikipedia: Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is ...
R Sahu's user avatar
  • 2,016
7votes
2answers
3kviews

How to populate Lazy object from database

I have these classes: public class Order { private Lazy<IEnumerable<Volume>> _volumes; long ID { get; private set; } string Description { get; private set; } IEnumerable&...
Tea With Cookies's user avatar
6votes
4answers
5kviews

How to avoid pollution of logic with lazy-loaded async properties

To be able to scale I would like to use async programming. It works really well if I have to read something from db and push to frontend, however I do not know how to use it correctly in blobs of ...
Shadow's user avatar
6votes
1answer
1kviews

Is it better to use lambda functions or boolean variables to record state

I have heard some people claiming that boolean state variables are generally bad and should be avoided when possible. Apparently in many cases it is possible to put state into lambda functions, ...
Michael Veksler's user avatar
6votes
2answers
2kviews

Does laziness yield more race conditions?

I recently ran into a race condition while accessing a configuration setting. After examining what I could of the code, I came to the conclusion that the Configuration class' laziness1 was the source ...
user avatar
6votes
0answers
2kviews

Entity Framework - Loading Related Entities Explicitly

I have been using Entity Framework for a few years. I have flip-flopped between calling out to repositories in my business logic or using lazy loading to retrieve data as I work my way through the ...
Travis Parks's user avatar
5votes
4answers
4kviews

What is a good pattern for combined caching and reinitialization?

I have a situation where I have three requirements: Lazy initialization - don't create the collection until asked for it Caching - keep the collection in memory on the object Reinitialization - be ...
Nicole's user avatar
  • 28.2k
4votes
2answers
2kviews

Lazy loaded property signatures in business objects

Let's say I am designing business objects around a poorly optimized database that have no ability to change. I have a Person object with a ShippingAddress property. The ShippingAddress is very ...
TheCatWhisperer's user avatar
4votes
1answer
1kviews

Webpack and Lazy Load for large-scale Web Application

Background I am trying to develop with Webpack and JavaScript. Webpack would bundle all source code into one single file. When application becomes large, the file would be very large and cause ...
Ben Cheng's user avatar
4votes
1answer
467views

Is it ever appropriate to lazy load properties?

Consider the following contrived program: class Program { static void Main(string[] args) { var myClass = new MyClass(); var stuff = myClass.MyProperty; // this takes 5 ...
Will Ray's user avatar
3votes
3answers
6kviews

REST Lazy Reference Create GET or POST?

I have a REST API where: GET or POST /foo/{foo_id}/bar?a=1,b=2,c=3 and GET /bar/{bar_id} both yield 200 { bar_id: <GUID>, foo_id: <foo_id>, a: 1, b: 2, c:3 } When no matching bar is ...
Blake Mitchell's user avatar
3votes
1answer
1kviews

Why does this static field always get initialized over-eagerly?

I am looking at this excellent article from Jon Skeet. While executing the demo code, Jon Skeet says that we can expect three different kinds of behaviours. To quote that article: The runtime could ...
TheSilverBullet's user avatar

153050per page
close