Java ( and DCI

95 views
Skip to first unread message

Trygve Reenskaug

unread,
Sep 15, 2012, 3:47:46 AM9/15/12
to DCI-object-composition
It seems that Java 8 has new DCI-friendly features. In particular, the Interface is now augmented with default methods (Virtual Extension Methods). Sounds like a form of Traits. Probably worth looking into for you Java people. (You probably know more about this than I do).


Stephan Herrmann

unread,
Sep 16, 2012, 9:06:33 AM9/16/12
to object-co...@googlegroups.com, try...@ifi.uio.no
Trygve,

I know it is tempting to think of default methods in Java 8 as some late arrival of some form of multiple inheritance / Traits, whatever you name it :)

Incidentally (ironically?) I'm responsible for implementing this feature for Eclipse, so I had a look at the (still not finalized) specification.

From all I saw, I can advise the use of default methods only along the original intention: to facilitate interface evolution. Library vendors can now add methods to interfaces that are already in use (i.e., implemented) by clients.

Given that composition using default methods would be purely static, any data object that potentially plays multiple roles in multiple contexts would need to statically declare to implement all those role interfaces. As a result conflicts between methods from different interfaces become possible. The sad news is: Java 8 will not bring any means for disambiguation in this situation: if an inherited default method happens to be override-equivalent with any other inherited method this will simply be flagged as a compile error. For real-life use as an implementation of roles the concept would need better support for isolating different roles. Sorry to say.

best,
Stephan

Risto Välimäki

unread,
Sep 16, 2012, 9:28:30 AM9/16/12
to object-co...@googlegroups.com

Given that composition using default methods would be purely static, any data object that potentially plays multiple roles in multiple contexts would need to statically declare to implement all those role interfaces. As a result conflicts between methods from different interfaces become possible. The sad news is: Java 8 will not bring any means for disambiguation in this situation: if an inherited default method happens to be override-equivalent with any other inherited method this will simply be flagged as a compile error. For real-life use as an implementation of roles the concept would need better support for isolating different roles. Sorry to say.

Indeed. I also had a look at "virtual extension methods" in Java 8, and while those have their uses, there is no way you could use them for DCI.

Even Scala Traits are better for DCI, although they also are not feasible solution. Trait-Roles cannot be applied to objects at runtime Just In Time. That means, your existing objects can't play any Trait-roles, unless you instantiate a new object with trait and then inject your current object state into that newly created one. What a mess. You'll also have to take care of re-create that object afterwards without the Trait. Finally, stacking contexts using same objects would bring this whole house of cards down.

Scala Traits are useful tool, but almost useless for DCI. The only exception to this is that if you do web programming, it might be feasible to re-create objects from database rather than "injecting" roles somehow.

Anyway, you can do full scale DCI on Scala just now, only the syntax is stupid until I implement Marvin-like injectionless Roles into it.

-Risto



best,
Stephan



On Saturday, September 15, 2012 9:44:32 AM UTC+2, trygve wrote:
It seems that Java 8 has new DCI-friendly features. In particular, the Interface is now augmented with default methods (Virtual Extension Methods). Sounds like a form of Traits. Probably worth looking into for you Java people. (You probably know more about this than I do).


--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To view this discussion on the web visit https://groups.google.com/d/msg/object-composition/-/Nc0EzzzMHOUJ.

To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.

Reply all
Reply to author
Forward
0 new messages