Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Click here for the latest updates on Groups Message search

Messages

  Messages Help
Advanced
What methods live where (Entities vs Services)   Topic List   < Prev Topic  |  Next Topic >
Reply < Prev Message  | 
Hi all,

I'm still fairly new to DDD but I'm working through it. What I am
trying to understand is when methods appear in Entities and when Services.

For example if we take the following scenario:
In a shopping web site you can set up an account and buy things on
credit. You then have to make payments off of the account. To do
this the customer logs on and navigates to make payment where they
enter their credit details.

A payment comes back with a result.

* NOTE: This is another issue. MakePayment() is a command yet it
needs to return the result of the command.

Now this is where the domain and infrastructure cross and services vs
entities becomes a little complex (for me). The account is owned by
another system and the provider to make payments is owned by another
system. The result of making a payment can happen in a few days time
as the banking system itself works through and eventually tells the
account to change its balance.

How should this be modelled in DDD? Before DDD I just had a
PaymentService with a MakePayment(payment) method and that was that!

Some ideas I've had are along the lines:
class ApplicationService
{
private Account accountBeingAccessed;

public Result ProcessPaymentOnCurrentAccount(IPaymentDetails
paymentDetails)
{
IPaymentRequest paymentRequest =
accountBeingAccessed.CreatePaymentRequest(paymentDetails);
PaymentResult result = IPaymentServices.ProcessPayment(paymentRequest);

accountBeingAccessed.AddPaymentResult(result);

return result;
}
}

And the IPaymentServices should exist in the domain but be implemented
in the infrasturcure layer.

Does the above sound correct or is it more correct to say:
Account.ProcessPayment(IPaymentDetails);
PaymentResult result = Account.GetResult(IPaymentDetails);

And the account entity acceses the service which is again implemented
in the infrastructure layer?




Mon Jan 8, 2007 4:08 pm

jupitermoon_...
Offline Offline
Send Email Send Email

< Prev Message  | 
Expand Messages Author Sort by Date

Hi all, I'm still fairly new to DDD but I'm working through it. What I am trying to understand is when methods appear in Entities and when Services. For...
jupitermoon_beam
jupitermoon_...
Offline Send Email
Jan 8, 2007
4:21 pm

Can I add to the following this example? The web system keeps a record of client's activity (a contact history). Therefore in the domain I have an object...
jupitermoon_beam
jupitermoon_...
Offline Send Email
Jan 8, 2007
4:41 pm

... does it persist? The domain object may depend on an abstract representation (i.e. interface or abstract class) of the infrastructure (see Dependency ...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 8, 2007
8:13 pm

I think I may have solved the contact. Firstly the ContactHistory is part of the Domain as I would wish to do Customer.ContactHistory but as correctly pointed...
jupitermoon_beam
jupitermoon_...
Offline Send Email
Jan 9, 2007
11:03 am

... internally then the following is perfectly legal: When you say "domain objects", I assume you mean Entities. Repositories, Entities, Value Objects, and...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 9, 2007
2:53 pm

My understanding is that one problem DDD is supposed to address is the "anemic domain model". Factories create Entities. Repositories return previously created...
Bob Hanson
mnbob70
Offline Send Email
Jan 9, 2007
3:45 pm

Jeff, Bob has articulated my query quite elegantly: if we start moving methods into services we risk making our domain turn sick and pale. With respect to...
jupitermoon_beam
jupitermoon_...
Offline Send Email
Jan 9, 2007
4:32 pm

... moving methods into services we risk making our domain turn sick and pale. Sorry for the misunderstanding. I wasn't advocating moving entity behavior into...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 9, 2007
5:23 pm

Nice example but it confuses me because it goes against the advice I was given in a different email thread. That advice said that Entities should not directly...
Bob Hanson
mnbob70
Offline Send Email
Jan 9, 2007
6:42 pm

According to my understanding of DDD: 1. Should Entities directly use repositories? Entities should use whatever they need to, in order to execute the business...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 9, 2007
7:20 pm

Jeff Lowe: "Typically transactions aren't a concern of the domain model." I am not talking about the implementation using, for example, database transactions....
Bob Hanson
mnbob70
Offline Send Email
Jan 9, 2007
7:51 pm

... transaction? The actual purchase (e.g. clicking on the last button in the purchase process) would invoke a single operation (either on a domain object or ...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 9, 2007
8:47 pm

Hi All, In a layered application architecture as illustratered below:- - presentation layer - Domain Layer - Data access layer without making the entities...
Shepard Towindo
sqlcertified
Offline Send Email
Jan 9, 2007
8:49 pm

... circular references since each layer could end up using the entities and Both the presentation layer and the data access layer should have a compile-time...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 9, 2007
9:05 pm

If the data access layer depends on the domain layer how does data move from the data access layer into a repository? Are your domain layer repositories just...
Bob Hanson
mnbob70
Offline Send Email
Jan 9, 2007
9:30 pm

... repository implementations reside in the data access layer? That's how I do it. Among other things, it easily allows for mock implementations for unit...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 9, 2007
9:39 pm

Moreover, a repository implementation is illustrative of Uncle Bob's dependency inversion principle, whereby the data access layer is dependent on the domain...
Chris Gardner
chris_gardner76
Offline Send Email
Jan 9, 2007
10:07 pm

The application layer is an appropriate place to ensure atomicity in your example. My guess is some application layer object (perhaps a command object) would...
Chris Gardner
chris_gardner76
Offline Send Email
Jan 9, 2007
10:23 pm

... should not ... I think the problem you mentioned comes from the fact that the same word "Repository" is used for two different topics: 1. Repository as...
aabelro
Offline Send Email
Jan 10, 2007
8:07 am

Bob, I too have been trying to get to the bottom of these questions. Lucky for me, I've been able to hammer this out with actual code. Here's my ... ...
John Ryan
john_s_ryan
Offline Send Email
Jan 24, 2007
6:46 pm

... secondary ... possible. John, Thanks for your concise answers! Can you tell me, do you find yourself creating "odd" value objects to dodge entity objects...
joethebigshmoe
Offline Send Email
Jan 24, 2007
7:13 pm

John: if you never let entities depend on repositories, then how to you implement a method like Customer.getOrders(DateRange) when you don't want Customer to...
Randy Stafford
randalparker...
Offline Send Email
Jan 24, 2007
7:39 pm

... Good question. After reading YOUR post, answering these questions, Randy, I'm starting to already shift from "Absolutely Not" to "Avoid it if you can" So,...
John Ryan
john_s_ryan
Offline Send Email
Jan 25, 2007
4:24 pm

The example below points out part of my disconnect. CustomerDAO <<Repository>> OrderDAO <<Repository>> I thought a DAO is not a repository and instead a DAO...
Bob Hanson
mnbob70
Offline Send Email
Jan 25, 2007
4:56 pm

... in the implementation of the repository. I see 2 different design patterns for repositories: The first is the repository specified as an interface in the...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 25, 2007
5:45 pm

I considered the interface approach, but ended up choosing the concrete class approach. One of the responsibilities of the repository as a concrete class is...
Stasko, Roger
rogerstasko
Offline Send Email
Jan 26, 2007
12:51 am

So, this is a bit of a nuance...but we're trying to be rigorous, here...I get it. In an idealized environment, absolutely yes. And then I'd ask myself "am I...
John Ryan
john_s_ryan
Offline Send Email
Jan 27, 2007
8:01 am

Wow...yeah, sorry Joe....I'm not tracking...give it another go....
John Ryan
john_s_ryan
Offline Send Email
Jan 25, 2007
4:10 pm

On Wed, 24 Jan 2007 06:59:54 -0000 ... I think this is a good ideal, but will not work often enough to say "absolutely not". Especially when large datasets...
Stephen Haberman
f1l1t0v
Offline Send Email
Jan 24, 2007
7:30 pm
First  | < Prev  |  Last 
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help