Home > Articles > Software Development & Management > UML

  • Print
  • + Share This
This chapter is from the book

7.3 Interactions

A state diagram provides a static view of the entire state space of an object at some level of abstraction, from the complete system down to simple primitive objects. Because the complete behavior of a state-driven object can be represented by a sufficiently detailed state model, state models are said to be constructive. This means that they can be used to fully generate executable code for the object.6

What state diagrams do not show are typical paths through the state space as the system is used, nor are they effective at showing how collaborations of objects interact. Such interactions are captured as scenarios. Scenarios may not visit all states in all the participant objects nor activate all transitions, but they provide an order-dependent view of how the set of objects is expected to behave under some set of conditions with a specific ordering of external and internal stimuli. Because a scenario does not have enough information to fully define the complete behavioral model of an object, scenarios are said to be partially constructive. They can add operations and event handling to a state model, but they do not fully define the model.

There are two methods for showing scenarios that are particularly useful in real-time systems. The primary notational form for scenarios is the sequence diagram, which shows order but not strict timing. The second is the timing diagram, which is best used when strict timing must be shown. There is a third, the diagram formerly known as a collaboration diagram but in UML 2.0 called a communication diagram. A communication diagram is basically an object diagram showing the message sequences as being attached to the links between the objects and indicating ordering with numbers on the messages. This last form is used rather infrequently and so will not be discussed here.

7.3.1 Sequence Diagrams

Sequence diagrams are (by far) the more common way to show scenarios, as discussed earlier in this book. Sequence diagrams use vertical lines to represent the objects participating in the scenario and horizontal directed lines to represent the messages sent from one object to another. Time flows from top to bottom; that is, messages shown lower on the page take place later than ones above it. The basic syntax and semantics of sequence diagrams have been discussed in Chapter 3. The focus in this section is to discuss how sequence diagrams may be usefully employed in the constructions of analysis object models.

Sequence diagrams are representations of specific interactions among the elements of a collaboration. They only tell a part of the story (what happened in this particular case) and not what always must happen (a specification). As such, sequence diagrams are a way to detail a use case. The sequence diagram helps to capture the operational perspective of a set of elements, such as a system, and the actors with which it interacts, or a set of elements inside a system. As we construct our object analysis model, we can use sequence diagrams to capture how the elements in the object analysis model interact to achieve the higher-level interaction described in the use case scenario.

The other use of sequence diagrams has to do with validation, the use of sequence diagrams as either a debugging tool or as a test vector. CardioNada Scenarios Example

It would be useful to look at the interaction of the instances in the pacemaker model. In a real development project we would create many sequence diagrams. Some of these sequence diagrams would be for the communications with sending and receiving messages, with and without errors. Other sequence diagrams would show the interactions necessary to achieve the pacing behavior, most likely several in each of the pacing modes. Still other sequence diagrams would depict the interaction of the communications and the pacing system to show how the programmer sets and queries the pacing modes and parameters. In this chapter, we are going to focus on pacing in AAI.

In this case, I am going to use the executability characteristics of the Rhapsody tool to both drive and monitor the execution of the model. First, to help drive the model, I will create a statechart for the Heart Chamber actor. We call this "instrumenting the actor" because we are creating executable behavior for the actor to help us explore how the objects inside the system interact to make sure that we got it right. This is almost exactly the same process as creating the «test buddy» class we saw previously in the calculator example. It differs in a couple of important ways. First, the actor is outside the scope of the pacing subsystem so we can't rely on the pacing subsystem to connect the actor with the parts of the subsystem automatically—we'll have to do that ourselves. Secondly, instrumenting the actor is less obtrusive in the model of the system, since the actor must use the specified interfaces and services. The statechart for the actor is shown in Figure 7-22.

07fig22.jpgFigure 7-22. HeartChamber Actor Statechart

We can see that the HeartChamber actor primarily acts like a heart. It beats at the rate held in the attribute timeToNextBeat. It can have randomness if we set the local attribute isRandom to TRUE. When it beats, it invokes the beat() method on the VoltageSensor to which it connects (which in turn sends an evSense event to the AtrialModel in this case). It accepts evPaceStart and evPaceStop events sent to it from the OutputCapacitor to which it connects. Code Listing 7-6 shows the code used to create the pacing subsystem and heart chamber instances. All but the sections between //#[and //#] are generated automatically by Rhapsody. The two lines of code between those marks were added to allow the heart chamber to send events to the voltage sensor, and to allow it to receive events from the output capacitor. The Object Execution Framework (OXF ) code starts up the framework so it can begin processing events and executing the state machines.

Listing 7-6. CardioNada main()

int main(int  argc, char*  argv[]) {
    if(OXF::init(argc, argv, 6423))
            HeartChamber * p_HeartChamber;
            Pacing_Subsystem * p_Pacing_Subsystem;
            p_HeartChamber = new HeartChamber;
            p_Pacing_Subsystem = new Pacing_Subsystem;
            //#[ configuration PacingOnly::DefaultConfig
            // set the heart chamber to send events
// to first voltage sensor
            // set first output capacitor to send
// its pace events to the heart chamber

            delete p_HeartChamber;
            delete p_Pacing_Subsystem;
            return 0;
            return 1;

A word about debugging and testing: When I build systems using the UML, I want to debug and test at the same level of abstraction at which I design—that is, I want to test and debug in UML, not in the underlying source language or the even-more underlying assembly language. While I may, at times, find it necessary to drill down to those levels of detail, the vast majority of my testing and debugging ought be at the model level, not the code level. For this reason, Rhapsody provides a rich set of debugging and testing tools that we'll use here. I bring this up now because once we begin to look at the sequence diagrams it is important to know how they were created mechanically (via the insertion of events, for example) as well as to understand that these sequence diagrams were generated automatically by Rhapsody as the system was executed.

When testing or debugging state-based objects, one of the basic things you need to be able to do is to insert events. Rhapsody provides a number of means to do this. Figure 7-23 shows one way—a dialog box that can be opened that allows the user to select the object and event to be inserted into the running model. It should be noted that Rhapsody also provides a means to call operations as well (not shown here). Figure 7-24 shows a different way. Rhapsody allows you to "webify" a model; that is, mark which elements you wish to monitor and/or control via a standard Web browser and then automatically generate such a Web page and to insert a Web server in your application. This is an extremely useful feature because it allows you to monitor and control a system via the Internet even while it is running on the actual target hardware (provided, of course, that it supports TCP/IP and can connect to the Internet). In the figure, we see two panes in the browser—the left identifies the elements that I've specified that I want to monitor or control, and the right presents the elements that I can use. We see that I can view (and set) the value for timeToNextBeat, set the heartMode, and isRandom Boolean attributes, and even send events such as evPace and evPaceStart (which takes a single int parameter). I can also construct custom views, picking among the elements I want to view together.

07fig23.gifFigure 7-23. Inserting Events

07fig24.gifFigure 7-24. Debugging with a Web Browser

Lastly, I also want to be able to see various features of the objects in the running system. Figure 7-25 shows the debugging view for the HeartMonitor. We see all the current attributes and even the links connecting the HeartMonitor to the VoltageSensor. The instance is identified by its name rather than by its memory address, making it much more useful. With these basic tools, I can control and monitor the execution of my system, whether it runs on my desktop, on the actual target hardware connected to the desktop, or on a machine thousands of miles away. Pretty cool, huh?

07fig25.gifFigure 7-25. Debugging View

The ability to debug systems is a crucial one, so even if you're not going to generate the system from the UML model,7 you must still be able to answer the question "Is this right???" about the model you've constructed. These debugging tools allow you to run your system and validate that it is doing the right thing.

Now, back to our main subject—the sequences of interaction of the pacing subsystem parts. The first sequence, shown in Figure 7-26, captures the creation of the two primary objects, the HeartMonitor and the Pacing_Subsystem, and how, in turn, the Pacing_Subsystem creates its internal parts. The ones shown are the instances of the AtrialModel, VoltageSensor, and OutputCapacitor. Note that there are other instances created as well, such as the VentricularModel instance and another instance each of the VoltageSensor and OutputCapacitor. Since we're not using them in this scenario, I didn't draw those instance lines and the creation messages to those instances are therefore not shown.

07fig26.jpgFigure 7-26. CardioNada Sequence 1—Creation and Initialization

The calls we entered into the main() shown in Code Listing 7-6 appear in the sequence diagram right after the construction of the system objects; we see getSensorInput() and setPaceChamberOutput() sent from the main() (as represented by the collaboration boundary) and the Pacing_Subsystem instance.

Since the statechart of the HeartChamber begins immediately we see the timeout events on the HeartChamber lifeline and the invocation of the VoltageSensor::beat() operation. Then from the debugger, we enter the enablePacing and toInhibited events.

Figure 7-27 shows an example of pacing. Notes were manually added to the automatically generated sequence to aid understanding. This figure is, in fact, a continuation of the scenario shown in Figure 7-26. In Figure 7-27 we can look at the interaction among the instances. At the top of the figure we see the timeout that causes the transition of the AtrialModel from its Refractory to its Waiting state. The transition action, a call to VoltageSensor::enable() lets the VoltageSensor turn on the hardware to listen (in the real system).

07fig27.jpgFigure 7-27. CardioNada Sequence 2—Pacing

Next we see something interesting. The HeartChamber times out and sends a beat to the VoltageSensor, which in turn sends an evSense event to the AtrialModel. Even as that happens, though, the Atrial Model state machine times out before it receives the evSense event. Therefore it proceeds to pace the heart even though the heart just completed a pace.8 Such race conditions occur frequently in real-time systems and it is good to see that the evSense event is appropriate discarded when that occurred.

The pacing of the heart is accomplished by first disabling the VoltageSensor and then invoking the OutputCapacitor::enable() method (which passes the amplitude of voltage pulse to be delivered). The pace is completed with the OutputCapacitor::disable() call. Then the Atrial model waits for a period of time (its refractory period) to allow the electrical charge in the heart to dissipate before reenabling the VoltageSensor.

The next sequence diagram, Figure 7-28, is a continuation of the previous one. In this case, the HeartChamber "beats" and invokes the VoltageSensor::beat() method. This method then sends an evSense event to the AtrialModel. It is received, causing the Atrial model to exit and then reenter its Waiting state. This causes the timeout that will invoke the pacing behavior to retrigger and start over. This is exactly what was desired in the SelfInihibited mode of operation.

07fig28.gifFigure 7-28. CardioNada Sequence 3—Inhibiting Calculator Scenario Example

In the previous section, we saw how the scenarios allowed us to examine and ensure that the pacemaker was pacing properly. In this section, we'll use scenarios to make sure that the Calculator is doing the same.

At the black-box level of testing, we can just pump mathematical expressions in one end of the Calculator and look at standard output to see if the value is correct. However, unit testing is all about the white-box view: making sure that the internal pieces of the system are doing what they are supposed to be doing. Scenario-based testing can allow us to insert events, change values, and invoke behaviors to actually demonstrate that objects are doing so and the interactions are what we expect.

In this case we can take a few simple expressions and run them through the various parts of the Calculator. In this way, we can examine them and see if we are convinced that the parts are all doing the right thing.

In this effort, we'll take advantage of the multiple configuration features of the Rhapsody tool, just as we've taken advantage of the model-level execution, debugging, and code-generation features previously. We'll create another configuration of the system, called Debug, that generates instrumentation in the code, allowing the generated application to talk back to Rhapsody. This feedback lets Rhapsody animate, via dynamic color-coding, the various states of the objects and dynamically construct the sequence diagrams during the execution of the system. We used these features in the previous section to create the sequence diagrams we looked at, but now we'll create a debug configuration of the Calculator as a separate item. This allows us to, at the click of a button, generate either a production version of the application, which we could ship off to a customer, or a debug version. The underlying model is the same either way, which greatly facilitates the testing of our model, since changes to the model we make as a result of testing and debugging automatically appear in the production version.

Figure 7-29 shows the Setting pane of the features of the Debug configuration of our calculator. The difference between this and the default (production) configuration is that instrumentation mode is set to Animation. This tells Rhapsody to insert macros in the generated code that send information back to the Rhapsody tool when events are processed, method calls are invoked, and attributes are changed. This allows Rhapsody to construct the dynamic visualizations of the application execution. Note that both configurations have Web Enabling checked. The Advanced button allows us to set which things are webified in the generated system, and so control whether this configuration has monitoring and control of internal portions of the system or just to enter expressions and see results.

07fig29.jpgFigure 7-29. Debug Configuration

It is common to have multiple such configurations. Some will have debugging capabilities enabled while others won't; some will be targeted at desktop systems such as Windows or Solaris, while others will be targeted at embedded RTOSes, such as VxWorks or OSE.

For the purpose of this debugging effort, let's examine what happens when we process the expression 2*(3+4). This simple expression allows us to ensure that we process both the addition and multiplication operators as well as parentheses properly. To create the figures for the scenario, I used the webify interface to enter in the expression and start things going. The Debug configuration sets the webify interface and the model animation features active.

The first figure (Figure 7-30) starts after the objects are created. The CharParser instance parses the characters in the expression string, identifies the kind of character it is (digit, operator, or white space), and sends them off to the Tokenizer via events such as evDigit or evOp, along with the actual character. The Tokenizer has the more interesting job—to construct the tokens from the incoming events. We see that it begins constructing the number token when it receives the first evDigit event through its invocation of the beginToken() method. The next event received is an evOp, passing the * character. Now the Tokenizer knows that the number is complete (after all, the number could have been 2345.78, in which case it would have had to construct the number token from seven characters instead of just one). It can now pass the complete number token off to the Evaluator via an evNumber event. The Evaluator simply pushes the number onto the stack. It calls reduceUnary() to reduce a unary –, if one was present.

07fig30.gifFigure 7-30. Calculator Scenario 2*(3+4) page 1

The Tokenizer also begins the operator processing. When it receives the next character (the open paragraph operator), it sends the * operator off to the Evaluator, which pushes it onto the operator stack. Note that since all operators are single characters, we could have sent off the * operator immediately. However, a design decision was made to allow for multiple character operators in the future, such as ++ and +='. This would allow subsequent versions of the Calculator to have variables and more elaborate behavior.

Figure 7-31 picks up where the previous figure leaves off. The Evaluator pushes the * operator. The CharParser meanwhile sends the digit 3 to the Tokenizer. The latter now sends the ( operator off to the Evaluator, which pushes it onto the operator stack. The processing continues with the + operator inside the parenthesis.

07fig31.gifFigure 7-31. Calculator Scenario 2*(3+4) page 2

Figure 7-32 continues the scenario with the digit 4. Now the Tokenizer can send the operator + to the Evaluator. The Evaluator now wants to see if it can apply the operator, so it calls reduce(). It cannot, as it happens, so it pushes the operator onto the operator stack. At this point, the number stack has the value 3 at the top, followed by 2 (the number 4 hasn't been pushed onto the stack yet). The operator stack has + at the top, followed by ( and then *.

07fig32.gifFigure 7-32. Calculator Scenario 2*(3+4) page 3

The next character is the ) operator. The processing continues in Figure 7-33. We see that the last number, 4, is pushed on the stack. The last token is a special one, called end of string (EOS). That forces the evaluation of the last operator, ). This calls the operation reduceSubExpr(), which does a reduction until a left parenthesis operator is found. We see that the Evaluator checks to ensure that the next operator is not a left parenthesis (after all (5) is a perfectly legal subexpression). Since it is not, the Evaluator pops the operator (a +) and two operands off the number stack, does the math (actually performed in the body of the reduceFactor() method), and pushes the result (7) onto the number stack. Then the ( is popped from the operator stack and discarded.

07fig33.gifFigure 7-33. Calculator Scenario 2*(3+4) page 4

The final reduction is done by processing the EOS event in the Evaluator. This is shown in the last of these figures, Figure 7-34. The reduceFactor() method is called (since we're processing a multiplicative operator) and we pop the operator from the stack (*), the two operands (7 and 2), do the math, and push the result on the stack (14). Since we're at the end of the string, we call displayResult(), which pops the value off the number stack and sends it to standard output.

07fig34.gifFigure 7-34. Calculator Scenario 2*(3+4) page 5

In a book, this sequence seems long and involved, as it is spread across five figures. In a tool, however, the entire scenario is a single diagram, and may be scrolled and zoomed as necessary.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020