Implementing Manager Models with a domain model

In my previous post I stated that I *think* I'm starting to move toward the Manager Model.  One of the reasons for this is because I want consistency in my API's.  I don't want some actions to be performed via a entity object, and other actions to be performed through a Manager.  If I do fully embrace the Manager Model the question now becomes do I complete abandon my domain model, or does it just become lighter?  My initial thought is that it just becomes lighter.  The business logic and workflow for the actions that I perform within my applications will move out of the domain model and into the manager model.  The thing I struggle with is the amount of behavior to pull out of my entity objects.  I've grown somewhat attached to the behavior, the ability to call .Save(), .Delete(), .FindOne(), .FindAll() right off my entity objects is something I like.  Besides just being something I like, the existing behavior also would make the implementation of my Manager (we're really talking about services here so why do I keep calling them managers?) Service a lot easier. 

public class CustomerService {
     public CustomerSaveResponse SaveCustomer(Customer aCustomer) {
        if(aCustomer.Save()) {
          /// blah blah
        }
        return new CustomerSaveResponse();
     }
}

Should behavior on my entity objects stay or go? 

# re: Implementing Manager Models with a domain model

Friday, March 12, 2004 12:15 AM by Lamont    
I would think the Manager/Service model would dictate you pull that functionality out of your Entity objects. It would entail the Entity objects just being objects that hold some state while operations performed on these objects would be performed by the Manager/Service. You could further expand this by introducing Service "agents" that perform tasks on behalf of the manager/service, therefore making the agents do the dirty work and allowing the manager/service be simply a facilitator.

It's a difficult question/decision. Especially since you've made considerable investment already in the domain model.

# re: Implementing Manager Models with a domain model

Friday, March 12, 2004 12:53 AM by Steve    
I like the idea of the agents. Shadowfax does something similar don't they?

Although I have made a pretty decent sized investment in my domain model I don't think it would be *too* painful to make the switch. Most of the work performed by my domain model is handed over to other objects (Persisters, Loaders, etc.) which I could call directly from my Service/Manager layer, I'd just need to pass along a couple additional parameters.

# re: Implementing Manager Models with a domain model

Friday, March 12, 2004 1:27 AM by Lamont    
Yes, Shadowfax uses a similar pattern, but it's a little more elaborate in that agents are invoked through what I'll call a "message dispatching pipeline". To adopt something like that would force you to further break down the role of the manager so it'll provide somewhat of a service transport and pipline (channeling) architecture.

Therefore, in your scenario, the manager would receive "messages" (loose intepretation here) via a particular transport type, and based on what the contents of the "message" is, you route it through a pipe to the designated agent. Keep in mind your Entity objects would be unaware of all this communication as they only hold state as a result of some operation performed by an agent.

Now granted you'd have a little more consistency in your APIs, but it comes at the cost if inserting more layers between the caller and underlying Entity containing the state you want.

# re: Implementing Manager Models with a domain model

Friday, March 12, 2004 1:40 AM by Frans Bouma    
"You could further expand this by introducing Service "agents" that perform tasks on behalf of the manager/service, therefore making the agents do the dirty work and allowing the manager/service be simply a facilitator. "
Correct. I think I called them submanagers somewhere, but agent is a better term I think.

Managers manage, that is: control and make decisions. Workers do the work. Just like in real life ;)

# re: Implementing Manager Models with a domain model

Friday, March 12, 2004 1:43 AM by Steve    
Yeah, at this point the Shadowfax architecture seems like overkill. I still need to dig into it a little more, and perhaps code against it a little to further develop my opinions on it.

Frans, I think "agent" is better too ;-) I think the idea of managers and agents could make for an interesting architecture. Now I need to find a project to try it out on!

Post a Comment

 
 
Prove you're not a spammer: 
1 + 2 =