4

What are possibles designs for implementation of the DCI (data, contexts, interactions) architecture in different OOP languages? I thought of Policy based design (Andrei Alexandrescu) for C++, DI and AOP for Java. However, I also thought about using State design pattern for representing roles and some sort of Template method for the interactions... What are the other possibilities?

Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52
  • From the original paper, there are also traits in Scala and open classes in Ruby. My Stete design pattern suggestion is wrong, because if I understand DCI correctly, the data should be isolated from knowing abou all the contexts in which it can be. – Gabriel Ščerbák Apr 23 '10 at 13:33
  • Your understanding is correct it's one of the main concerns of DCI to make what the system is (data) independent of what the system is – Rune FS Mar 05 '12 at 11:10

2 Answers2

6

Doing pure DCI is tough in most language you usually run into one of two problems. Statically typed languages such as Java usually ends up with some kind of wrapper solution which creates a self schizofrenia problem. Dynamic languages that let you attach new instance methods at will at run time often suffers from a scoping issue. The RoleMethods are still available when the object is no longer playing the role.

Best fits I know of for different languages

  • Marvin: Design for DCI and as such has full support
  • Ruby using Maroon. If you are using the maroon gem (or similar) then there's full support for DCI in Ruby.
  • Java: Qi4J
  • C# Extension methods (Scoping issue and overload issue) possibly together with dynamic. I've had an implementation based on Clay but that creates an identity problem
  • Native Ruby: Method injection Scoping issue with methods being available when the object no longer plays the role
  • C++: Templates. Scoping issue method life span is the same as the object life span

if you take a look at fullOO you will find examples in a few languages. Including in my own project Marvin which is a language specifically designed to support DCI. At present most of Marvin is identical to C# so you could say it's an extension to C# more than a language of it's own right.

Rune FS
  • 21,497
  • 7
  • 62
  • 96
2

In Java, without byte-code generation, I would use Decorator pattern for contexts, however I will instead of classes decorate interfaces, which will be more flexible. Data than will be represented through classes implementing the interfaces. The interactions will be done using manual dependency injection into Template methods.

Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52
  • 1
    DCI is tough in Java but using Qi4J get's you very close. The main problem that arises from different implementations in Java is identity problems. DCI is about objects and not classes. The decorator pattern is class based. In DCI the behaviour of an (already instantiated) object is extended with role methods. Those methods are internal to the context not some other class nor some other object. In other words you can't do DCI with the decorator pattern – Rune FS Apr 04 '12 at 13:38