what_is_the_advantage_of_distributing_the_interaction_algorithm_in_the_rolemethods_as_suggested_by_dci_instead_of_centralizing_it_in_a_context_method

This is an old revision of the document!


What is the advantage of distributing the interaction algorithm in the RoleMethods, as suggested by DCI, instead of centralizing it in a Context method?

It is really a design decision. It is always possible to centralize the interaction code by rewriting the RoleMethods to become instance methods in the Context. The Roles are instance variables in the Context. The method names may have to be changed to avoid name clashes, and any occurrence of 'self' in the code must be replaced by the corresponding role name.

However, a difference between that kind of procedure orientation and object orientation is that in the former, we ask: “What happens?” In the latter, we ask: “Who does what?” Even in a simple example, a reader looses the “who” and thereby important locality context that is essential for building a mental model of the algorithm.

A centralized architecture may be OK in simple cases, but the decentralized (DCI) architecture leads to more sophisticated mental model and code.

The natural model is for Roles to act like actors in a play, interacting with each other to carry out the work of the system.

Most of the time, putting the algorithm in the Context is global procedural thinking: an all-knowing algorithm orchestrating conscribed objects to perform low-level operations on the behalf of the procedure. You can of course do that in DCI and of course can do it through generic interfaces, but it's not DCI.

Once in a while though, this Context-centric algorithm could have a place. The example is the age-old example of drawing a shape on a window, where each object comes from its corresponding class hierarchy. If the draw algorithm doesn't easily decompose in a way that fits naturally in either class or in any corresponding roles, it belongs in the Context. This is the exceptional case, however.

what_is_the_advantage_of_distributing_the_interaction_algorithm_in_the_rolemethods_as_suggested_by_dci_instead_of_centralizing_it_in_a_context_method.1390173318.txt.gz · Last modified: 2014/01/19 23:15 by gazoot