Re: The DCI Architecture: A New Vision of Object-Oriented Programming
Posted: Mar 26, 2009 6:06 AM
> Just how important are traits (or equivalent programming
> language constructs) to DCI? In the Scala example, we
> mixin the trait to the Account class. But it seems
> apparent that, at least for the article's example, we
> could implement the same in Java (without Qi4j) by
> injecting an Account into an instance of a
> Or, to put it another way -- in certain dynamic languages
> such as Ruby (hand waving alert:I am no expert on Ruby), I
> believe we could do a mixin without an explicit coupling
> between the methodful role/trait and the Account object.
> Is this a real advantage? Does the Scala implementation
> n lose something by coupling the trait to the Account?
I think a mixin in Ruby is an analogous concept to traits in Scala. The main difference comes from the fact that Ruby's mixins are dynamic and Scala's mixins are static. (In Scala, when you actually use a trait, mix it into a class, you can also call it a mixin.)
As far as the advantage of traits over dependency injection in Java, I think you can get the same functionality, but you'll end up with more code in Java. You can write by hand in Java what the Scala compiler does for you when you mix traits into classes in Scala. It's just a lot more code in Java. But it is also a level of abstraction effect. I think all that code required in Java would make it harder to think at the level you think of in Scala when working with traits.