DCI in Ruby

580 views
Skip to first unread message

Steen Lehmann

unread,
Jan 22, 2009, 4:05:33 AM1/22/09
to object-composition
I've uploaded two Ruby source files to the group. They are a first
attempt to implement a small part of DCI in Ruby. James was referring
to parts of these in a post, so I thought I'd post the whole thing.

There are two files since I'm trying out two different approaches to
dealing with the context. In both examples, the context also plays the
role of the actual interaction, orchestrating the participants and
invoking methods on their roles.

In the "without context" example, the roles do not refer back to the
context, but are passed everything they need by the context. In the
"with context" example a current context is maintained for the roles
to access. This has some interesting future possibilities with regards
to nesting of contexts, and scoped resolution, if we decide to go that
way.

Roles are implemented as modules in Ruby, and mixed onto each domain
object instance by the context, as appropriate. This is highly
dynamic, and solves all identity-related issues, but has its own
problems. For example, the risk of name collisions with existing
methods or other roles. Also, there is currently no neat way to remove
the role again. These concerns would be solved in a language with
scoped mixins (fingers crossed for Ruby 2.0 :)

Please try:

ruby account_example_without_context.rb
or
ruby account_example_without_context.rb

and get back to me with any comments or questions. Suggestions for
improvements are welcome.

-- Steen

Reply all
Reply to author
Forward
0 new messages