I'm glad that you liked the presentation.
The MoneyTransferService I describe in the presentation is a simplified but typical service in the applications I work on.
public class MoneyTransferServiceImpl implements MoneyTransferService {
public MoneyTransferServiceImpl(AccountRepository accountRepository,
BankingTransactionRepository bankingTransactionRepository) {...}
}
public BankingTransaction transfer(String fromAccountId,
String toAccountId, double amount) throws MoneyTransferException {
Account fromAccount = accountRepository.findAccount(fromAccountId);
Account toAccount = accountRepository.findAccount (toAccountId);
fromAccount.debit(amount);
toAccount.credit(amount);
TransferTransaction txn = new TransferTransaction(fromAccount,
toAccount, amount, new Date());
bankingTransactionRepository.addTransaction(txn);
return txn;
}
}
(and, yes, this could probably be shorted to return fromAccount.transferTo(toAccount, amount) , and money shouldn't be a double :-) )
The services are invoked by the web tier, e.g. Spring MVC controller. Each service method is a few lines of code that takes object ids + other data as parameters; calls some repositories to load some entities and then invokes some methods on those entities to do some work etc. You could probably characterize this as an application service rather than domain service but if your services are simple like this one then having a separate domain service isn't generally valuable. However, if the service was fatter and manipulated, for example, XML messages or DTOs, then moving the domain logic into a separate domain service might be a good idea.
Chris
--
Enterprise POJO consulting - http://www.chrisrichardson.net
Author, POJOs in Action - http://www.manning.com/crichardson
Enterprise POJOs blog - http://chris-richardson.blog-city.com
Speaking in 2007 at JavaOne, SpringOne, the Colorado Software Summit, the Spring Experience
On 8/31/07, dkode8880 <dkode8880@...> wrote:
Chris,
This is an excellent description covering many topics. There was a couple of things in
there I was not aware of.
Can you go more in depth on how services should be used in the domain? I was under the
impression that the Service Layer should be a combination of multiple Repositories to
accomplish some sort of group work. Is this accurate?
Thanks again for the excellent webcast!
Sean
--- In domaindrivendesign@yahoogroups.com, "Chris Richardson"
<chris.e.richardson@...> wrote:
>
> Hi,
>
> Back in June at the SpringOne conference I gave a talk on improving
> application design with a rich domain model. The video of the talk has
> now been published. You can find out more about the talk and links to
> the video and slides by going here
> http://www.chrisrichardson.net/springOne2007.html .
>
> It would be great to get your feedback.
>
> Chris
>
> --
> Author, POJOs in Action - http://www.manning.com/crichardson
> Enterprise POJO consulting - http://www.chrisrichardson.net
> Enterprise POJOs blog - http://chris-richardson.blog-city.com
> Speaking in 2007 at the Colorado Software Summit and the Spring Experience
>