Questions tagged [lazy-initialization]
The lazy-initialization tag has no summary.
37 questions
1vote
3answers
176views
Ensuring run-once behavior in a multi-threaded environment via volatile lambdas?
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(...
0votes
2answers
677views
Best way to code lazy loading outside the model in vanilla c#
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 ...
2votes
1answer
1kviews
Is it a good idea to use a Lazy wrapper type to encapsulate lazy initialization in Java?
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 ...
-3votes
1answer
2kviews
Is it good practice to call service layer through domain object getters?
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; ...
2votes
1answer
118views
Modelling seats of a table in a social game
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 ...
0votes
2answers
924views
Is there a better way to use Lazy<T> than what I'm doing?
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-...
1vote
2answers
485views
C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?
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 ...
1vote
1answer
688views
Throttling the factory function of a Lazy<T> instantiated with LazyThreadSafetyMode.PublicationOnly
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 ...
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, ...
2votes
2answers
1kviews
Is it a good idea to use "lazy val" for correctness?
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 ...
0votes
1answer
206views
In what other locations besides infinite streams and infinite lists is memoized lazyness useful?
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 ...
0votes
3answers
1kviews
Extending the concept of Lazy Loading, to also unloading
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 ...
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 ...
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 ...
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 ...