Friday, December 16, 2011

DCI for dummies

The metaphor of DCI is a theatre. The context is the director. Chooses who plays what, instruct them how to do it and then let them play.

  1. Expose use-cases (context) as first-class citizens of your code. 
  2. Each use-case selects which objects are needed for this use-case. 
  3. Extend the objects only with the roles that are needed in this use-case. 
  4. Start the interaction. 

Buying a product.
  1. UserBuysAProduct object, that can be executed. 
  2. Objects/actors needed: user, shop 
  3. Extend user with a Buyer role and shop with ProductCatalogue and OrderManager. 
  4. call shop.buy_product(user, product) 


Anonymous said...

In your example you have a shop by a product. Isn't a product an actor?

I would think of something along the lines of this:

Jan Dudulski said...

You should write your's own framework ;)

Andrzej Krzywda said...


The product is definitely exposed in the use case. Is it an actor? I'm not sure. User and shop use the product somehow, but it doesn't pass my current definition of an actor.

And yeah, it could be implement in a way you're suggesting. At some point there must be a connection to the shop (playing the OrderManager role) to turn it into an order. That's why I put it in the shop object.