Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is DCI and how can it fit with Rails?

Tags:

A recent debate with a co-worker about different approaches to design and code the models in a Rails application brought me across DCI in the context of Rails.

However, I just can't seem to wrap my head around that entire concept, even after going over this example application.

Currently, I tend to just go more or less "by the book" when writing a Rails app.

So there are a few things I'd like to ask --

  • What is DCI and what are its advantages when implemented alongside MVC over plain old MVC (and vanilla ActiveRecord in Rails) ?
  • And how can it be implemented in Rails (or in other words, what's with all the modules) ?

Edit

I'd like to even further expand my question in the context of RoR - is another level of abstraction between the models and the controllers in Rails recommended? How widespread is it in different-scale applications?

like image 681
GeReV Avatar asked Mar 13 '12 03:03

GeReV


1 Answers

DCI is a paradigm and hence much more than a way to design an application. It's a way to think about modelling as well as structuring code. One of the important parts of DCI is keeping what the system is (the domain model) and what the system does (functionality) apart. DCI is not a different approach to solving the same problem as MVC so your first question can't really be answered. You can use MVC and DCI simultaneously which is no coincidence since Trygve Renskaug is the father of both MVC and DCI. He recently answered a similar question to this on the google group 'object-composition'.

The example you've linked to violates some of the basic ideas such as keeping roles private to the contexts and I couldn't actually find a single context either but that could be due to spending only a short time browsing the code.

I don't know RoR my self so I can't give you an RoR example but if you go to fullOO you'll find examples written in different languages including both Ruby and Marvin the first language designed for DCI.

EDIT There's no simply answer to the question "What is DCI" DCI is a paradigm, just like OOP is a paradigm. They both have the same roots and answering the above question is as complicated as answering "What is object orientented programming". Things are even more complicated by the fact that DCI is object oriented and OOP in all the major OO languages is actually class oriented and not object oriented. DCI aims at producing code where the interaction between objects at run time is visible in the code at compile time and in more general terms tries to mkae it easier to reason about the run time behavior from reading the code. The site I've linked to above is devoted to explaining what DCI is all about and also lists examples in a number of languages. Ruby being one of them

EDIT There's a book on ruby and DCI on it's way. The author is pretty active on object-composition and insightfull

like image 193
Rune FS Avatar answered Sep 27 '22 15:09

Rune FS