Unit 7 Flashcards

1
Q

Why must the conditions on a message send be mutually exclusive in a sequential system?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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?

A

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();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Suggest a reason why an object’s lifeline must branch in cases such as Figure 2.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Are the examples of sequence diagrams in Unit 6 generic or instance interaction diagrams?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you change the sequence diagram in Figure 3 to sound the car’s horn five times each time it moved forward?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does UML distinguish a synchronous message send from an asynchronous message send? How is a return from a synchronous message send indicated?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What properties of a message or a signal are used to express a timing constraint?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the main disadvantage of defensive programming?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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?

A

We are following the strategy of using one central class here.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Are use case objects consistent with the twin aims of high cohesion and low coupling (terms that were introduced in Unit 1)?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why might two objects of the same class respond differently to the same message?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the most common form of event that causes a transition between two states? How is it shown in a statechart diagram?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between an event and an action?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the main constraint on the kinds of action that may be shown in a state diagram?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an action sequence?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a guard, and how does it protect a transition?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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

A guest who is checking out cannot make the hotel full, so no guard is needed for the checkOut(aGuest) event.

18
Q

Why were guards introduced on the transitions for the checkout(aGuest) event in Figure 21?

A

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).

19
Q

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)?

A

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.

20
Q

Give an example of an architectural decision that would provide a general solution to the problem of unexpected messages.

A

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.

21
Q

What is an entry event, and how does it contribute to the maintenance of a state diagram?

A

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).

22
Q

What is the benefit of using an internal event as opposed to a self-transition?

A

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.

23
Q

What does a final state signify in a state machine?

A

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.)

24
Q

In what ways does a final state differ from an initial state?

A

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.

25
Q

Identify three problems associated with complex state diagrams that might arise when designing classes.

A

Classes with complex state machines can cause three kinds of problem.

First, it is harder to write the eventual code for such classes, since there are likely to be many conditional tests to identify the actual state.

Second, it is harder to test the class because of the number of choices of pathway through the conditional tests.

Third, it is much harder for external code to use a class correctly without some means of ascertaining the actual state of objects belonging to complex classes.

26
Q

Suppose the class Copy included the attributes returnDate, libraryNumber and classification. Which of those attributes are significant for a state machine for the class Copy that has two states called on shelf and on loan? Explain your choice.

A

State machines help model what might happen when a particular object receives a given message, since the behaviour of an object is influenced by the values of its attributes. A state machine tells you about the life history of an object. Therefore you can use the frequency of change of an attribute during an object’s lifetime as a means of choosing which attributes are significant when constructing a state machine. In the class Copy, for example, the attribute returnDate is likely to change often, as it reflects the transition between the states on shelf and on loan. However, attributes such as libraryNumber and classification will only change as a result of some reorganisation within the library (probably set during the creation of instances of the class Copy). The borrowing and returning of each copy by the library’s members do not affect them. Among other things, you might consider an additional attribute that records the actual date when a copy is returned (actualReturnDate, say) if you needed to investigate the notion of fines for overdue books.

27
Q

Suppose you implemented your design for a class without using a state diagram. Are there any subsequent activities where a state machine might help you as a developer? Briefly explain your answer.

A

You might need to develop state machines retrospectively.

For example, you might benefit by preparing a state machine when testing individual classes, to demonstrate that the behaviour of an object over its lifetime satisfies the relevant requirements for its class – usually for the purposes of verification.

In addition, a proposed change to a software system might introduce a need to prepare one or more statechart diagrams to show how an object’s state would be affected.

28
Q

In Section 4 you saw examples of message passing in state diagrams. In UML, what kind of event is a message?

A

A message is the commonest case of a call event.

29
Q

Is a signal a class? Briefly explain your answer.

A

A signal is a special kind of class. However, there are no operations associated with a signal, and its parameters are recorded as attributes. Because they are classes, signals may be related through an inheritance hierarchy, but they must be separated from the other classes in the software system.

30
Q

What is the difference between a time event and a change event?

A

A time event relates to a specific point in time or an interval. A time event is a Boolean test of a time expression, such as the length of time that must elapse between a named event and a subsequent action.

A change event takes place when a test condition evaluates to true at some point in time. A change event is not restricted to time; rather, the transition can fire when some condition is true, such as the level of liquid in a storage tank reaching some predetermined danger level.

31
Q

What kinds of event are entry and exit events?

A

They are both signal events, because they happen when a state transition occurs for whatever reason, such as a call or a time event. An entry event sets off an action sequence when a message causes a state to be entered. An exit event sets off an action sequence when a message causes a state to be left.

32
Q

What is a composite state in UML? Must composite states have initial and final states?

A

A composite state is one that contains some internal behaviour, which can itself be represented as a separate state diagram.

It is not compulsory to show an initial and a final state. However, you should use an initial state to show which substate is the default entry point.

33
Q

Consider the in library composite state for the class Copy in Figure 30. A composite state contains one or more substates, but does the outer state change while the internal state machine is working? Use the example to explain your answer.

A

No. The outer state represents the condition of being in any one of the substates. When the in library state is entered, the Copy object will be in one of the substates shown in Figure 30. When a Copy object is in a substate such as on shelf, it is, by definition, also in the in library state. When the Copy object leaves a substate, it leaves the in library state.

34
Q

What characteristics of events suggest that an object should respond to them when they occur?

A

An object should normally respond to:

  • events that are external, such as those from a point of sale terminal;
  • change or time events that require some response;
  • certain changes such as high/low temperature, in process-control systems, to avoid problems or even disasters.
35
Q

Do packages only contain classes?

A

No – they can contain any model element from UML. Among other things, you can include classes, use cases, associations and even other packages.

36
Q

Which modelling principle would lead you to form packages?

A

You should use a package to raise the abstraction level, suppressing any detail in a particular diagram that is not necessary to understand what the model is showing.

37
Q

Explain how it is possible to have two separate elements with the same name.

A

If you place the two elements in separate packages, they can have the same name. This is because each model element is identified by its name and the name of the smallest package that contains it.

38
Q

The stereotypes «import» and «access» allow you to ‘see’ through the ‘wall’ around a package. Which one can give rise to a naming problem? Which one provides the simpler traceability?

A

The «import» stereotype can give rise to a naming problem, because an «import» adds the names of the elements in the target package to the source package. The result is that, if an imported name clashes with an existing name, you have to qualify the imported elements withtheir package name in order to distinguish them.

The «access» stereotype allows simpler traceability, because other packages must use the full name of an accessed element, such as PackageName::ElementName.

39
Q

Suppose you used «access» to ‘see’ into a package. Can you see everything inside that package? Briefly explain your answer.

A

There is no guarantee that you can ‘see’ all the elements of the package. It is possible to control the visibility of elements within a package in the same way that you can control the visibility of the attributes of a class. An element of the accessed package can be marked as private, making it invisible to other packages that import this package and indicated with a ‘–’ character. Alternatively, it can be marked as protected, making it invisible to importers of the package but visible to child packages, and indicated with a ‘#’ character.

40
Q

What is a subsystem?

A

A subsystem is a package of elements that are treated as a single unit or model element. It is a coherent piece, or partition, of a system that is treated as a single abstraction. In effect, it is modelled as both a package and a classifier. It is a solution to the common problem of wanting a package to take part in interactions.

41
Q

What is the structure of a subsystem in UML?

A

A subsystem contains a behavioural specification and the things needed to implement that behaviour. There are three groups of elements in UML.

One group contains specification elements such as use cases, constraints and the relationships between them.

A second group contains the operations and, by implication, interfaces needed to meet the specification.

A third group contains the elements needed to implement the behaviour defined by the other groups. Thus the third group will contain classes, associations and named collaborations or patterns.