--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/object-composition/f40980af-c67b-448c-9216-3b11cbea5f21n%40googlegroups.com.
Hi Anton,
I would second the approach of looking from "the side." If I
understand what you're saying, then another way of saying it would
be a first-person perspective vs. a third-person perspective,
where third-person is looking from "the side."
For example, consider Rune's example of front-loading activities in a project planning system (inspired by Trygve's Prokon example):
https://fulloo.info/Examples/Marvin/FrontLoader/Listings/FrontLoader/
That's an example using the third-person approach, whereas the
first-person approach could look like this:
In this example, I think it's clear that the 'projectPlanner' role is overkill, since it's not doing anything other than calling the allActivities role, and there isn't even any data about the current user needed by this context.
Having said that, it's entirely allowed in DCI to bind null/nil
to a role if you want to add a role for semantic reasons only, and
I think people in this group probably have somewhat different
preferences about this. And to take your example, I could
definitely envision a PurchaseProducts context where Customer is a
role (whether Customer is bound to null or a real User object).
It's also valid to create roles to represent people or theoretical people who aren't necessarily the user of the Context you're writing. For example, consider this alternative version of the money transfer example (switching to trygve syntax now):
context
TransferMoney {
public TransferMoney(Currency amount, Account source,
Account destination) {
Banker = null;
Source = Source;
Destination = Destination;
Amount = amount;
}
role Banker {
void transfer() {
Source.withdraw();
Destination.deposit();
}
}
role Source {...}
role Destination {...}
role Amount {...}
}
(compare with the example
in the trygve repo which starts the transfer using a
Source.transferTo() method and has no Banker role.)
In summary, there are many different approaches that are all valid and can work, but which one is best depends on your particular Context and the mental model you want to convey.
Best,
Matt
To view this discussion on the web visit https://groups.google.com/d/msgid/object-composition/589EA8AF-61BA-4341-BA1F-0F5DF3D97735%40gmail.com.