This page is a repository for examples of DCI code. Programmers often let their code go through three stages:
Make it work. Make it right. Make it fast.
'Make it work' means that the code does what it is supposed to do and that there are no known bugs. 'Make it fast' comes later and is not our concern here. 'Make it right' is the goal of all the code posted here. It means that the code is easy to read and understand. We assume that the reader's mental model is founded on the DCI paradigm and that the code clearly exhibits this paradigm.
Our yardstick for evaluating the code is how it supports the reader's mental model. Classes are classes as they have always been. Only this time they can be much simpler since they do not describe system behavior. System behavior is realized by Contexts implementing system operations (which may be derived from use cases). A Context encapsulates a network of interacting objects. The objects are represented by the Role they play in the Interaction. The Roles are indirect addresses to the objects so that a reader can think in terms of interacting Roles rather than concrete objects. The reader should never be surprised by some kink in the implementation.
The system operation is realized by the collaboration of the participating Roles. The behavior of each Roles is given by its RoleMethods. The RoleMethods are parts of the Roles and, indirectly, of the participating objects. They naturally override the instance methods of these objects.
A Context is the namespace of its Roles. A Role is the namespace of its RoleMethods. This means that a Role is not visible from outside its Context, and a Rolemethod is not visible from outside the Role.
The examples are organized by programming language. Each set of examples is introduced by a short description of the language and its conventions for implementing DCI.
Squeak is a dialect of Smalltalk. DCI/Squeak is an extension of Squeak to support code written according to the DCI paradigm.
Go to DCI examples written in Squeak/BabyIDE
Go to DCI examples written in Ruby
Go to DCI examples written in C++
Go to DCI examples written in Marvin
Go to DCI examples written in Scala