From the creator of MVC, now comes... DCI, the new programming paradigm

Thu, 05.07.2012 dci, paradigm

Heck, it’s more than a year that I don’t fill my blog with some content, so here I am with an special entry.

Data, context and interaction, that’s the meaning of the acronym which describes the new programming paradigm proposed by Trygve Reenskaug, the creator of MVC himself (together with James O. Coplien).

So, if I have understood it well, they reckon that Object Oriented Programming is not really about objects, but about classes. Classes are actually that what we define, somehow living on themselves, but not very much flexible in what their different objects can do. When you want a lot of variability in the behaviour of those instances, you need lots of methods, or chains of subclasses, and much coupling in between. Well, (in Ruby there are modules that we can mix in, but) with DCI we are talking about the core capabilities of the language, so in this regard, it is more than a framework. If these ideas get accepted, they should probably be integrated in the language itself (that’d be cool).

Is it really that big an issue? Let’s see what DCI proposes:

  1. The instantiated objects modelling normal application data can play different roles along the execution of the program. Their methods should be compliant with an interface defined by the respective Role that they want to play. So every object able to do certain simple tasks (each one in its own particular way) could play a certain role. This Role therefore extends the capabilities of the object, independently of the class to which it belongs (now that’s polymorphism).
  2. Programmers should then declare algorithmic use cases inside a Context, assigning Objects to play different Roles depending on the scope of actuation.
  3. Finally, there is an Interaction taking place, which is what happens when you actually run the code (in the C language convention, the so called main routine), instantiating, calling some Context routines depending on different inputs, setting parameters which will propagate inside them, and so on.

What I most like about this proposal is that it surreptitiously includes and somehow explicits the concepts of Event-driven programming, in which the Context or use case can be reduced to be just a simple event handler, something I long for.
I can also imagine, that BDD should become a bliss, since stories and scenarios are already included inside the code.
It also allows for unconstrained behaviour of objects in a realistic, extensible and DRY manner.

Summarizing, business logic has finally found its place under the sun. The next big thing (and it is already more than 3 years old, aren’t we outdated!).

Some links:

By the way, I would have called it a more incisive name, like Role, Story, Action, but that’s not my butter anymore.

0 comments