Data-Context-Interaction

Definition
Provide an explicit representation of the use case to make the purpose of code more understandable.
Data-Context-Interaction architecture diagram

How does it work?

This pattern makes the use case an explicit entity. A use case is an action a user can perform on a system (add an object to a shopping cart, take out an insurance policy). The idea is that the application logic of a system is an implementation of use cases. These uses cases, however, are implicit in current OOP. There's no central use case class. It is distributed over many classes. Therefore it isn't clear how the classes work together from looking at the code alone. This means that what a system does is still for a large part in the heads of the programmers, and this is a hurdle for new developers that need to work on the system.

Data-Context-Interaction (DCI) tries to solve this by making use cases explicit. An ongoing attempt is implementing this idea in a new programming language called trygve, but it can be implemented in most other languages as well. The use case is then implemented as a context.

The context defines roles to perform the functions of the use case. Each role is simply a collection of methods. The methods (or scripts) are injected in an empty object. This stateless object is the role. Note that the role consists only of those methods that are necessary for this specific use case, whereas in current OOP practices, a class contains methods for multiple use cases. Multiple roles can be assigned to a single object.

When all roles have been instantiated, the use case can be executed. This process is called interaction

  • Data data from the database
  • Context Each use case is implemented as a separate context. This context contains roles.
  • interaction The execution of the play that involves the roles.

When should you use it?

  • In large systems with many use cases, that threatens to become incomprehensible.

Problems

  • This is not a widely used pattern yet, so there may not be much support. Experiment with it in a small-scale setting first.

Where does it come from?

It was created by Trygve Reenskaug (the creator of the well-known pattern Model-View-Controller) and James O. Coplien.

Links