Data, context and interaction

This is an old revision of this page, as edited by FrescoBot (talk | contribs) at 02:31, 9 June 2010 (Bot: links syntax and spacing). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

DCI

Data, Context and Interaction (DCI) is a paradigm used in computer programming. The pattern separates the ___domain model (Data) from Use cases (Context) and Roles that objects play (Interaction). DCI is complementary to Model–view–controller (MVC). MVC as a pattern language is still used to separate the data and its processing from presentation.

DCI was first introduced by Trygve Reenskaug, the inventor of MVC. The current formulation of DCI is mostly the work of Reenskaug and James O. Coplien.

Description

Data
Static data model with relations.
Barely smart data, that commonly abstracts the physical storage of the data. These data reflect the end user cognitive model of the computation. They correspond closely to the Model objects of MVC.
An example of a Data object could be a bank account. Its interface would have basic operations for increasing and decreasing the balance and for inquiring about the current balance. The interface would likely not offer operations that involve transactions, or which in any way involve other objects or any user interaction. Those operations belong instead in the Interaction part of DCI.
Data objects are the sort that relate to the classes that might come from ___domain-driven design, and such classes might use subtyping relationships to organize ___domain data. Though it reduces to classes in the end, DCI reflects a computational model dominated by object thinking rather than class thinking. Therefore, when thinking "Data" in DCI, it means thinking more about the instances at run time than about the classes from which they were instantiated.
Context
Use cases and algorithms in which data models are used through specific roles.
A Context is an object that is a collection of code that includes the roles for a given algorithm, scenario, or use case; and the code to map these roles into objects at run time. A Context is often implemented as a class that is instantiated as a Context object at the beginning of the enactment of an algorithm, scenario, or use case.
The scope of a Context is at the level of a whole algorithm, scenario, or use case, and each Context represents one or more use cases. A Context object is instantiated for each enactment of a use case for which it is responsible. Its main job is to identify the objects that will participate in the use case and to associate them with the roles whose responsibilities characterize the use case. Each role comprises methods, and each method is some small part of the logic of an algorithm implementing a use case. The role-to-object bindings that take place in a Context can be contrasted with the polymorphism of vernacular object-oriented programming. The overall business functionality is the sum of complex networks of methods decentralized in multiple roles. For a given use case enactment, each of these roles runs in the context of an object selected for it by the Context.
Each Context is a scope that includes identifiers that correspond to roles. Any role executing within that Context can refer to the other roles in that Context through these identifiers. These identifiers have come to be called methodless roles.
An example of a context could be a wire transfer between two accounts, where data models (the banking accounts) are used through source account and destination account roles.
Interaction
The Interaction is implemented as roles which can be assigned to data models.
A role is a programming construct that corresponds to the end user's mental model of some entity in the system. A role is a collection of responsibilities. Whereas vernacular object-oriented programming speaks of objects or classes as the locus of responsibilities, DCI ascribes them to roles. An object participating in a use case has responsibilities: those that it takes on as a result of playing a particular role. Most modern programming languages have a way to express roles, and to express the injection of role methods into objects, and implementation techniques vary depending the language. The injection can be fully dynamic at run-time in languages like Ruby and Python; it is more static in languages like Scala and C++. The Qi4j programming environment offers a way to express role method injection into objects in Java.
An example of a role could be a bank account being the source account.
”What the system does”

History

Multi-paradigm, role modelling.

Implementing DCI

Several example implementations exists: Smalltalk/Squeak, C++[1], C#[2], Ruby[3], JavaScript[4], Python, Qi4J (Java)[5] , Scala and PHP[6].

Implementation techniques differ in many ways in different languages. For roles, method injection is usually needed. Some languages have native support for roles, some other languages (Ruby) allows run time injection of methods, while in others (Java) pre-compiler tricks are needed to simulate DCI.

References