Unit 7 Flashcards
Why must the conditions on a message send be mutually exclusive in a sequential system?
If conditions were not mutually exclusive, more than one condition might be true. This would mean that multiple messages would be sent at once, leading to multiple receiving objects being active at the same time – violating the assumption that the system is sequential and not concurrent.
Figure 2 shows two conditional message sends originating at the same moment on the timeline, meaning that all the guards are evaluated before any message is sent. Could the same behaviour be implemented if the messages (and their conditions) were separated on the time line?
Yes, provided that the conditions were mutually exclusive, so that the first message could not affect the state of the receiver before the second message arrived. We might use code such as the following.
if (room.ready)room.accept(jill);
if (!room.ready)room.requestCleaner();
Suggest a reason why an object’s lifeline must branch in cases such as Figure 2.
The Room object will receive different messages depending on which branch is executed in the Hotel object. It makes no sense for the messages to arrive at just one lifeline, as that would imply that the Room object received all of the messages in a single interaction. Instead, we show a fork in the lifeline of the receiving object to reflect the fork of control in the sending object.
Are the examples of sequence diagrams in Unit 6 generic or instance interaction diagrams?
All the examples in the course text in Unit 6, except Figures 12, 17 and 18, are instance interaction diagrams, as they show a specific (concrete) sequence of messages. (Figures 1 and 2 of this unit are not pure generic interaction diagrams either, as they still contain concrete instances of certain classes.)
How would you change the sequence diagram in Figure 3 to sound the car’s horn five times each time it moved forward?
To get the horn to sound five times for every forward movement in the sequence diagram, you would add an iteration clause to the second, nested message:
*[j := 1..5] sound().
How does UML distinguish a synchronous message send from an asynchronous message send? How is a return from a synchronous message send indicated?
A synchronous message send has a solid arrowhead and a continuous shaft,
whereas an asynchronous message send has a stick arrowhead and a continuous shaft.
The return from a synchronous message send is marked by a stick arrowhead with a dashed shaft.
What properties of a message or a signal are used to express a timing constraint?
The sendTime and receiveTime properties of a message or a signal are used to express a timing constraint. In addition, a message label is required to express the time difference between the start and end points, as shown in the examples in Figure 8.
What is the main disadvantage of defensive programming?
The main disadvantage of defensive programming is that the constraints within each precondition end up being repeatedly checked in both the client and the supplier.
Which of the three strategies is being used when we place methods such as
createGuest(lastname: String, firstname: String, address : String)
in the Hotel class?
We are following the strategy of using one central class here.
Are use case objects consistent with the twin aims of high cohesion and low coupling (terms that were introduced in Unit 1)?
Yes and no. Yes, because high cohesion asks us to ‘do one thing and do it well’. A CheckerIn class should only support the one activity of checking in.
No, because having an extra class for each use case does introduce more coupling through the extra associations involved.
However, the new classes introduce barriers that limit the impact of a change to a software system.
Why might two objects of the same class respond differently to the same message?
An object’s behaviour will in general be affected by the values of its attributes, which are part of the object’s state. If two objects have different values for the same attributes, they are in different states, and therefore they might respond differently to the same message.
What is the most common form of event that causes a transition between two states? How is it shown in a statechart diagram?
The receipt of a message is the most common form of event that causes a transition between states. An event is used to label the transitions between the states. In a statechart diagram, a transition is labelled with the name of the relevant message, which includes any arguments for that message.
What is the difference between an event and an action?
An event is something done to the object, such as sending it a message.
An action is something that the object does, such as sending a message to itself or to another object. An action is an object’s reaction to an event.
What is the main constraint on the kinds of action that may be shown in a state diagram?
Actions should only refer to things that the object ‘knows’ about.
For example, they can refer to attributes, operations and links of the object, as well as to the parameters of the message that caused the transition. An action cannot refer to the state or attributes of another object unless there is some way for these other attributes to be known in a short time without requiring any state changes.
What is an action sequence?
An action sequence is an ordered series of individual actions that are associated with a particular event. They are written as a list separated by semicolons, and are performed sequentially in left-to-right order. Like actions, action sequences are atomic.
What is a guard, and how does it protect a transition?
A guard is a Boolean condition that is applied to a transition; the guard must be either true or false. A guarded transition can only take place when the specified guard is true.
Look at Figure 20, which only considers whether or not an object of class Hotel is full. Why are there no guards on the transitions for the checkOut(aGuest) event?
A guest who is checking out cannot make the hotel full, so no guard is needed for the checkOut(aGuest) event.
Why were guards introduced on the transitions for the checkout(aGuest) event in Figure 21?
The example in Figure 20 is incomplete. Figure 21 deals with both extremes – when the hotel is full and when it is empty – as well as the possible configurations between full and empty. This results in checkout(aGuest) occurring in three transitions, two of which (from not full to empty and from not full to not full) require guards to ensure mutual exclusion between them. For completeness, we added a guard to the remaining checkout(aGuest) event (from full to not full) as a check on the mutual exclusion between all three uses of checkOut(aGuest).
Figure 22 shows a simple statechart diagram for the class Copy. What should happen if the copy returned message arrives when an object of the class Copy is in the state on shelf (assuming that we are not using Design by Contract)?
Something has gone wrong. The state of the system does not describe the fact that the copy of the book is not on loan. There must be some means of indicating or recording an error, such as a message to a log file.
Give an example of an architectural decision that would provide a general solution to the problem of unexpected messages.
At an architectural level, we might introduce a single object of a class Error, which is globally accessible to objects in the software system. Such an object would be responsible for reporting errors due to unexpected messages, for example.
What is an entry event, and how does it contribute to the maintenance of a state diagram?
An entry event can be used where there are multiple transitions, with the same actions, leading to a particular state in a given diagram.
An entry event occurs every time an object enters the state that it annotates.
Entry events reduce the risk of introducing errors, because the action sequence is written once (associated with the entry event of the state) rather than many times (on each of the transitions leading to that state).
What is the benefit of using an internal event as opposed to a self-transition?
When there are entry and exit events that might interfere with a self-transition, an internal event is useful, as the entry and exit events are not triggered.
What does a final state signify in a state machine?
A final state is used to show the point or points where the object in question has finished processing or has reached the end of its life and will be destroyed. Although we might show more than one final state in a statechart diagram, each copy represents the same final state. (In the next subsection, you will see that a stop marker can be used to indicate that a composite state has finished executing.)
In what ways does a final state differ from an initial state?
There can be zero, one or more final states but at most one initial state.
A final state can be active for a period of time, whereas an initial state results in an immediate transition to a successor state.
A final state can have several incoming transitions and no outgoing transitions, but an initial state has no incoming transitions and only one outgoing transition.