Questions tagged [lazy-initialization]
The lazy-initialization tag has no summary.
37 questions
21
votes
6
answers
18k
views
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 ...
37
votes
6
answers
22k
views
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?
1
vote
3
answers
212
views
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(...
3
votes
3
answers
6k
views
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 ...
7
votes
2
answers
3k
views
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&...
0
votes
2
answers
700
views
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 ...
2
votes
1
answer
1k
views
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 ...
-3
votes
1
answer
2k
views
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;
...
6
votes
4
answers
5k
views
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 ...
6
votes
1
answer
1k
views
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, ...
0
votes
2
answers
1k
views
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-...
2
votes
2
answers
1k
views
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 ...
1
vote
1
answer
727
views
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 ...
1
vote
2
answers
518
views
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 ...
0
votes
3
answers
1k
views
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 ...