User Tools

Site Tools


what_is_the_relationship_between_classes_objects_roles_and_contexts

This is an old revision of the document!


What is the relationship between Classes, Objects, Roles and Contexts?

In contemporary programming languages, classes are the fundamental building block for objects. This “class-oriented” approach has long been promoted as object-orientation, but is highlighted by DCI as a too limited view on objects. Objects span over more than a single class, which has been acknowledged in mainstream languages by the rise of features like extension methods, traits and mixins.

A class serves well as a static data structure, a collection of defining properties and relations defined by system architects and domain experts. When a class is instantiated as an object however, that object will interact with other objects in ways that does not directly associate to its basic definitions. A pen does not know how to write, writing requires interaction between for example a pen, a human and a paper. From a system perspective, neither of these objects are a valid place for this collaboration between objects called “writing”, instead an encompassing system will define how writing should occur, and will access the concerned object properties when needed during the process.

Writing is a more generic process, or as DCI calls it, “Context”, than one that handles only the specific objects pen, human and paper. That's where Roles comes in. Writing can be done on basically any material, so in a writing Context it makes sense that the object paper should be called, or play the Role “Material” in the writing context. The same goes for the other objects:

  • The object Pen plays the Role Instrument in the Writing Context.
  • The object Human plays the Role Writer in the Writing Context.
  • The object Paper plays the Role Material in the Writing Context.

Inside the Context, the objects will have their interacting functionality (moving the instrument using the writer, testing material limitations, etc) attached as RoleMethods, which shows that objects span over more than just a class. These RoleMethods needs to be attached directly on the object to ensure proper identity reference (and cognition), but they cannot be defined on the class since we don't care what object is playing the Role anymore, we only refer to it as “the Material”. The only thing the object must do is fulfill the RoleObjectContract for the Role, but that's another topic.

Note that all the above definitions and terms are created in accordance with system architects and domain experts, to follow domain terminology and a given mental model as closely as possible.

Summary

  • A Class is a basic data structure for an object
  • An Object can play a Role in a Context
  • A Context specifies a network of communicating Objects as interconnected Roles
  • A Role is an identifier in a Context that abstracts away the object internals, focusing on communication and interaction.

See the Glossary for additional terminology details.

what_is_the_relationship_between_classes_objects_roles_and_contexts.1413933973.txt.gz · Last modified: 2014/10/21 23:26 by gazoot