by Doug Lea.
ProtocolCharts are a graphical notation for describing statefull interactions among objects. To a first approximation, they combine most of the properties of StateCharts that have beed adapted into standard OOA/D notations, along with those of Interaction Diagrams.
ProtocolCharts grew out of work on PSL (see ECOOP 95 paper and Sun Technical Report), a more formal specification system for open distributed object systems geared especially for CORBA. However, the version described here can be applied to nearly any OO notation system. I'll illustrate using a hacked-OMT similar to that used in the ``Gang of Four'' Design Patterns book.
The version illustrated here is one of the variants described in Design
Patterns. Here, the Subject sends a reference to itself
as an argument to notifywhen it is changed; the
Observer uses this reference to probe for values, and performs
a redisplay only if the state actually differs from that held in a cache.
There are two main views of Subject/Observer, structural and dynamic. The structure can be described in terms of hacked-OMT interface diagrams:
A few minor differences in convention from those in Design Patterns make ProtocolCharts simpler to construct:
Val. Concrete classes might for example
implement attributes via methods that interact with yet other
objects maintaining the representation. In fact, it is sometimes
possible for an implementation not to represent an attribute at
all -- an attribute might hold of an object without it
``knowing'' that it does. In keeping with this view, attributes
are referenced using ``function notation''. For example, the
state value of some Subject s is referenced as
Val(s).
Also, as a convenience, reference-style attributes are represented
redundantly. They show both the links to the classes they can
refer to, as well as pidgin-C++ textual declarations. (Of course,
it is equally possible to use Pidgin-Smalltalk or Pidgin-Java or
whatever for a base syntax.)
oneway
qualifiers indicating asynchronous operations that do not bear
replies (not even void). These are useful even
in non-distributed applications when describing operations that
are ``logically'' asynchronous in that callers don't care when
they complete.
In words, the main motification protocol is that when a Subject
s receives a changeVal request, for each
Observer o in its set of Observers, it makes sure that
its abstract state Val(s) has been set, sends a
notify message to the observer, and then replies to
whoever called changeVal. When the Observer
o receives the notification, it ``probes'' s
by asking for its currentVal. If the returned value
differs from the value recorded as CachedState, the
Observer sends itself a display request. The details of
what happens when an Observer receives that display
request aren't important to this aspect of the protocol.
The associated ProtocolChart is:
The basic properties of ProtocolCharts are as follows. (More detailed and formal descriptions of semantics are contained in the PSL papers).
in(...) describing the fact
that certain messages have been received.
out(...) describing the fact that
certain messages have been issued.
One important difference between situation nodes and the nodes used in normal state diagrams is that message issuance/reception is listed as as an aspect of a situation itself, not as a part of a transition.
Messages may be given names (by convention all uppercase).
Messages are listed in pidgin C++ surrounded by angle-brackets. A
reply to another message M is listed as
reply[M](return-val). Similarly, an exception reply is
listed as throw[M](excptn). An in(...) or
out(...) expression can optionally contain a by
(...) suffix to indicate or emphasize which entity receives or
issues the message.
In principle, a situation node can list any mixture of descriptions mentioning any number of entities. However, in practice, they nearly always describe the abstract state and/or actions of a single object. In this case, it is a good idea to color-code them, so like-colored nodes all include descriptions of the same entity.
As with StateCharts, situations in ProtocolCharts can be nested to
indicate alternative subconditions. An implict (or explicit)
default subsituation can indicate cases in which none of
the listed alternatives apply.
Two or more instances (realizations) of the same situation
may occur ``simultanously''. For example, in the above
Subject/Observer protocol, as many instances of the very first
situation occur as there are Observers in Obs(s). The
ProtocolChart allows (but does not mandate) that each instance can
proceed concurrently.
Unlike raw code descriptions, these links do NOT represent pure one-step-at-a-time flow -- any amount of time and any number of other nonconflicting actions may occur between the listed situations. ProtocolCharts describe the minimal required actions of participants, but do not rule out the existence of other compatible actions in implementations. In fact, there is no notion of an ``atomic transition'' at all in ProtocolCharts. Any number of other (nonconflicting) situations may occur in between those that are listed. Among other things, this permits refinement of protocols in subclasses. (The lack of a clear basis for splicing in other unlisted actions etc., in refinements or implementations is a bug in most state and interaction notations as applied to OO.)
Scopes ``grow'' across the links of a protocol. This mirrors the fact that protocols accumulate state across time. Any situation expression may refer to any name declared in any of its predecessors. So the flow of links across nodes should not loop. (More technically, there are no implicit ``fixed point'' conventions. These would add complexity without adding usability.)