views:

210

answers:

5

In my project,i have workflow which operates on multiple entities to accomplish a business transaction. What is the best place to represent the workflow logic? currently i just create a "XXXManager" which is responsible for collaborating with entity objects to conclude a business transaction. Are there other options?

A: 

DDD might not be exactly about this sort of thing, so I would suggest taking a look at the Service Layer architectural pattern. Martin Fowler's book Patterns of Enterprise Architecture is a good book that will explain it. You can find the description of the pattern on Fowler's web site as well.

RibaldEddie
A: 

Creating Workflow systems can be a daunting prospect. Have you considered using Workflow engines?

If I understand you correctly, you will need to create a manager which keeps track of the different transactions in the worklflow, related to user. There are probably other ways of doing it - but I've always used engines.

Steven
+1  A: 

Usually there is a domain object that should actually handle the control which is mistaken for an "entity".

Is there an instance of something that gets created as a result of this workflow? If so, the workflow logic probably belongs in there. Consider "Order" in the model below.

alt text

Oder is both a noun and a verb. The "Order" is the object that created as a result of "Ordering". Like any good class, it has both data and behavior (and I don't mean getters and setters). The behavior is the dynamic process that goes with the data, i.e., the ordering workflow. "Order" is the controller.

This is why OO was invented.

Doug Knesek
One might say that OO domain modeling is about nounification of verbs.
Wouter Lievens
+1  A: 

I'd say you're doing the right thing having something collaborate with multiple entities to get something done. The important thing is that each entity (and indeed each service) should have a single responsibility.

The overarching workflow you're talking about is something that you can consider as a part of your Application Layer.

According to Paul Gielens (paraphrased) The Application Layer’s responsibility is to digest the course-grained requests (messages/commands) to acheive a certain overarching goal. It does this by sending a message to Domain Services for fulfillment. It then also (optionally) decides to send notifications to the Infrastructure Service.

But then what is a 'Service'?! It's an overloaded term but one that's described well (again, by Paul Gielens)

You might also want to read about Onion Architecture for more ideas...

rohancragg
txn for the Onion Architecture reference, interesting article!
Sander Versluys
A: 

To the great answers, I'd like to add "domain events" (link is just to one possible implementation) which is something Evans himself has come to put more focus on ("increased emphasis on events").

Martin R-L