Content deleted Content added
→Context: added references. |
m →Interaction: added references. |
||
Line 28:
===Interaction===
The interaction is "what the system ''does''."<ref name="Artima" /> The interaction is implemented as Roles which are played by objects at run time. These objects combine the state and methods of a data (___domain) object with methods (but no state, as Roles are stateless<ref>{{cite web |last1=Coplien |first1=James |title=Why must roles be stateless? |url=https://fulloo.info/doku.php?id=why_must_roles_be_stateless |website=DCI FAQ}}</ref>) from one or more Roles<ref name="Artima" />. In good DCI style, a Role addresses another object only in terms of its (methodless) Role. There is a special Role called <code>self</code> which binds to the object playing the current Role. Code within a Role method may invoke a method on <code>self</code> and thereby invoke a method of the data part of the current object. One curious aspect of DCI is that these bindings are guaranteed to be in place only at run time (using a variety of approaches and conventions; [[C++ template]]s can be used to guarantee that the bindings will succeed<ref>{{cite web |title=DCI Examples for C++ |url=https://fulloo.info/Examples/C++Examples/ |website=fulloo.info}}</ref>). This means that interactions, the Role methods, are ''generic''. In fact, some DCI implementations use generics or templates for Roles.
A Role is a stateless programming construct that corresponds to the end user's mental model of some entity in the system<ref name="DCI Paradigm" />. A Role represents a collection of responsibilities. Whereas vernacular object-oriented programming speaks of objects or classes as a multiplicity of responsibilities, DCI ascribes them to Roles. An object participating in a use case has responsibilities: those that it takes on as a result of playing a particular Role. Most modern programming languages have a way to express Roles, and to express the injection of Role methods into objects, and implementation techniques vary depending on the language. The injection can be fully dynamic at run-time in languages like [[Ruby (programming language)|Ruby]] and [[Python (programming language)|Python]]; it is more static in languages like [[Smalltalk]]-[[Squeak]], [[Scala (programming language)|Scala]] and [[C++]]. The Qi4j programming environment offers a way to express Role method injection into Java objects.<ref name="Qi4j">[http://www.qi4j.org/ Qi4j framework]</ref> Java 8 [http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html default method] on interfaces can be used to implement Roles in a typesafe way.
In the above money transfer use case, for example, the Role methods in the SourceAccount and DestinationAccount enact the actual transfer.
|