Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [lazy-initialization]

Filter by
Sorted by
Tagged with
1 vote
3 answers
211 views

I'm coding an enum strategy pattern where one of the strategies makes use of an ScheduledExecutor: class ControllerImpl { //... boolean applyStrat(StratParam param) { getStrat().apply(...
walen's user avatar
  • 355
0 votes
2 answers
700 views

I have to implement a LazyLoading on the properties of my Entites Class. I can't use any framework and external dll (nugets package are forbiden, I can't use Entity Framework or Castle Dynamic Proxy ...
user1594914's user avatar
2 votes
1 answer
1k views

In our code base, we have several static or instance members that we would like to initialize lazily. If the initialization cannot yield null, It's easy to implement. Otherwise, one could use an ...
mperktold's user avatar
  • 151
-3 votes
1 answer
2k views

Tell me anybody, is it good practice to call service layer methods through domain object getters? Let me show you with an example: public class User { private long id; private String name; ...
Artem's user avatar
  • 3
2 votes
1 answer
142 views

Assume we want to model a table where players can sit down to get together to play a game (card games, dice games, ...). Assume a few properties associated with each seat class Seat { public int ...
Benj's user avatar
  • 169
0 votes
2 answers
1k views

I recently started trying to use the Lazy class to implement lazy loading. However, I'm finding that doing so does not seem to have any advantages over simply implementing it myself via a null-...
Sarov's user avatar
  • 403
1 vote
2 answers
518 views

A couple of months ago I wrote a C++ program for computational mathematics that was supposed to compete with a highly optimized C code. After a while I did manage to get it fast enough to beat the C ...
mathreadler's user avatar
1 vote
1 answer
727 views

When you use the constructor of Lazy<T> requesting the valueFactory and mode parameters (I mean this one) you can specify LazyThreadSafetyMode.PublicationOnly. This way you can prevent the Lazy ...
Enrico Massone's user avatar
6 votes
1 answer
1k views

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
2 votes
2 answers
1k views

In Scala, declaring a val as lazy means that its value won't be evaluated until it's used for the first time. This is often explained/demonstrated as being useful for optimization, in case a value ...
Joseph Sible-Reinstate Monica's user avatar
0 votes
1 answer
212 views

Haskell is one of the few non-strict languages out there. In his paper Why Functional Programming Matters, John Hughes uses (memoized) lazy evaluation (as well as higher-order functions) to implement ...
Qqwy's user avatar
  • 4,947
0 votes
3 answers
1k views

A system that sometimes will need to use a pretrained machine learning model. That model is about 10Gb on disk, and when loaded uses about 10Gb of RAM. Loading it from disk takes a nontrivial amount ...
Frames Catherine White's user avatar
4 votes
1 answer
1k views

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
  • 349
21 votes
6 answers
18k views

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
  • 899
8 votes
1 answer
1k views

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
1 vote
1 answer
451 views

TL;DR: I have noted that some tutorials are using an extra method call to retrieve a variable, in my case EntityManager of Doctrine. Is it generally a good idea to use such extra method call, when it ...
Dennis's user avatar
  • 8,267
6 votes
4 answers
5k views

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
  • 361
3 votes
3 answers
6k views

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
1 vote
1 answer
4k views

I was trying to find a concrete example online but I couldn't find one that also used one of the class' other attributes. So, can this be done more succinctly with a Lazy<T> object? public ...
user107775's user avatar
4 votes
1 answer
526 views

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
  • 141
7 votes
2 answers
3k views

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
1 vote
1 answer
2k views

I guess I don't believe in myself as a good programmer but I found out this method on my own (not suggestion I'm the first one to do it, but I didn't follow a guide) so it must be broken somehow. $q ...
Ingó Vals's user avatar
4 votes
2 answers
2k views

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
2 votes
2 answers
2k views

I know lazy loading is required when an expensive database call is being made. It would make sense using lazy loading in this example. The below example is in the context of asp.net so it's thread ...
Howls Hagrid's user avatar
2 votes
1 answer
1k views

I was looking for the idiomatic way to implement thread-safe lazy initialization for a configuration collection retrieved from the DB inside a Spring bean. I decided to adapt the initialisation-on-...
Adam's user avatar
  • 187
0 votes
1 answer
135 views

Is there something special(i.e. a design pattern being related) to a method named create()? Background The case is, I often make some instances of objects (of the same class/prototype). These objects ...
humanityANDpeace's user avatar
6 votes
2 answers
2k views

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
-1 votes
2 answers
178 views

(1) The oldmakeutility looks at timestamps, and if the output is newer than the input, it skips (pointless, time-consuming) re-compilation of e.g. C files. The same is true for many languages and ...
Frank N's user avatar
  • 131
0 votes
1 answer
240 views

I am making an iOS app which contains museum gallery: user can look through exhibits and then select info about it, etc. On the exhibit screen I have two ScrollViews that are different, but are being ...
Richard Topchii's user avatar
6 votes
0 answers
2k views

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
  • 2,583
2 votes
2 answers
856 views

I often see model classes with properties like this: public IList<Note> Notes { get; set; } public bool HasNotes { get; set; } Where the list is initialized lazy, but the boolean property is ...
Philipp M's user avatar
  • 123
3 votes
1 answer
1k views

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
3 votes
1 answer
894 views

Trying to be a better programmer I have an application that keeps track of Roles and Permissions, I had classes for Role and Permission which were just value objects. class Role { int RoleID ...
tunmise fasipe's user avatar
37 votes
6 answers
22k views

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
  • 1,739
5 votes
4 answers
4k views

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.3k
10 votes
4 answers
2k views

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.3k
1 vote
1 answer
667 views

I created a app using Microsoft's WPF. It mostly handles data reading and input as well as associating relations between data within specific parameters. As a total beginner I made some bad design ...
Ingó Vals's user avatar