15
votes
Accepted
DDD Injecting Services on Entity Methods Calls
It's totally fine to pass a Domain service in an entity call. Say, we need to calculate an invoice sum with some complicated algorithm that can depend on, say, a customer type. Here is what it might ...
14
votes
DDD Injecting Services on Entity Methods Calls
I am shocked to read some of the answers here.
It's perfectly valid to pass domain services into entity methods in DDD to delegate some business calculations. As an example, imagine your aggregate ...
10
votes
DDD Injecting Services on Entity Methods Calls
Is it within best practices of DDD and OOP to inject services on entity method calls?
No, you should not inject anything inside your domain layer (this includes entities, value objects, factories and ...
8
votes
Accepted
Is it better to use lambda functions or boolean variables to record state
Using these kinds of object-oriented or functional techniques can be super neat and elegant. If you need a fancy name for what you are doing here, I suggest the State Pattern, with function objects ...
8
votes
DDD Injecting Services on Entity Methods Calls
The key idea in DDD tactical patterns: the application accesses all data in the application by acting on an aggregate root. This implies that the only entities which are accessible outside of the ...
5
votes
Extending the concept of Lazy Loading, to also unloading
The normal approach to caching would be to put stuff into the cache when you need it and remove it when you try to put a new thing into the cache but don't have enough memory to do so.
You then have ...
4
votes
Best way to code lazy loading outside the model in vanilla c#
Your implementation is correct, but it's a wheel that did not need to be reinvented. There's a Lazy<T> class that already provides this functionality.
MSDN link
var myLazySchool = new Lazy<...
4
votes
Accepted
Is it a good idea to use a Lazy wrapper type to encapsulate lazy initialization in Java?
There is nothing wrong with lazy initialization. In fact, that's a very common use case. I've written Lazy<T> helpers myself, and lazy initialization is one of the better uses of the singleton ...
4
votes
DDD Injecting Services on Entity Methods Calls
The answer is: definitely NO, avoid passing services in entity methods.
The solution is simple: just let the Order repository return the Order with all of its LineItems. In your case the aggregate ...
3
votes
Webpack and Lazy Load for large-scale Web Application
All mature JavaScript loading and bundling tools, from Webpack to RequireJS to SystemJS, provide techniques for doing this.
In Webpack it's enabled by a feature known as code splitting.
In SystemJS ...
3
votes
DDD Injecting Services on Entity Methods Calls
Generally speaking value objects belonging to aggregate don't have repository by themselves. It's aggregate root's responsibility to populate them. In your case, it's your OrderRepository's ...
3
votes
Is there a name for the counterpart of the lazy loading pattern?
Lazy Loading the design pattern is the opposite of Eager Loading the design pattern.
This is when instead of deferring the load to hopefully avoid it, you perform the load immediately to avoid any ...
3
votes
Accepted
Is it a good idea to use "lazy val" for correctness?
Yes, it is considered okay in general. A relatively common use is to initialize fields of a supertype when they have to depend on the state of a subtype (but even there you need to be careful). See ...
3
votes
In what other locations besides infinite streams and infinite lists is memoized lazyness useful?
Some other situations that jump to mind:
Iterative processes that need to use the results of some earlier values but not others (which provides for simple ways of efficiently implementing processes ...
3
votes
Extending the concept of Lazy Loading, to also unloading
Many garbage collected languages have the concept of a WeakReference<T>, including Java and .Net. This allows your code that loads the data to have a reference that can be garbage collected. ...
3
votes
Modelling seats of a table in a social game
A Seat should know whether or not it is occupied. Simply because someone joins or leaves the game doesn't mean you need a new Seat(). The player has just vacated that spot at the table.
That being ...
2
votes
Accepted
C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?
I’d look into the Object Pool pattern that basically does the recycling you mention yourself.
It’s actually how both Android and iOS handle the problem of “staggering” while scrolling on a list of ...
2
votes
Accepted
Throttling the factory function of a Lazy<T> instantiated with LazyThreadSafetyMode.PublicationOnly
As there is no standard way to get such a behaviour, and if you really need it, then by all means that is a valid approach.
It may even be desirable to implement your own helpers to facilitate easier/...
2
votes
Accepted
Is there a better way to use Lazy<T> than what I'm doing?
Those two versions do different things.
Consider what happens if the DataException is thrown and caught. The first will search _contactRepo at most once. The second will search _contactRepo each ...
1
vote
Best way to code lazy loading outside the model in vanilla c#
Your solution is not thread-safe. The existence check and the retrieval of data are two separate methods. So they are not treated as one, atomic method, which might result multiple calls of data ...
1
vote
Accepted
Is it good practice to call service layer through domain object getters?
is it good practice to call service layer methods through domain object getters?
I strongly suspect you would come to regret that over the lifetime of a project.
The usual pattern is that your domain ...
1
vote
C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?
As long as no heap memory is allocated, creating objects in C++ (when no calculations are performed in the constructor) isn't more expensive than calling a function and assigning individual variables, ...
1
vote
REST Lazy Reference Create GET or POST?
It's not black and white. Section 9.2.1 of RFC 9110 answers your question completely:
Request methods are considered "safe" if their defined semantics are essentially read-only; i.e., the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
lazy-initialization × 37c# × 12
java × 6
design-patterns × 6
design × 3
architecture × 2
object-oriented × 2
c++ × 2
php × 2
domain-driven-design × 2
multithreading × 2
builds × 2
async × 2
inversion-of-control × 2
memory-usage × 2
lambda × 2
initialization × 2
static-access × 2
javascript × 1
object-oriented-design × 1
programming-practices × 1
rest × 1
programming-languages × 1
performance × 1
terminology × 1