Unit 7 - More on dynamic modelling – states and activities 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, resulting in multiple receiving objects being active at the same time – leading to the possibility of non-deterministic behaviour.
SAQ 1
What is the main disadvantage of defensive programming?
The main disadvantage of defensive programming is that the same constraints within each precondition may be checked repeatedly in different operations.
SAQ 2
Which of the three strategies for implementing use cases 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.
SAQ 2
Are use case objects consistent with the twin aims of high cohesion and low coupling?
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 introduces more coupling through the extra associations involved. However the introduction of these new classes limits the impact of a change to a software system.
SAQ 2
What is a state machine and what does it do?
A state machine is a model that shows how an object changes from state to state in response to events.
p. 161
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.
SAQ 3
What does a final state signify in a state machine?
Final states are used to show the point or points where the object in question has finished processing. Its activity has been completed.
SAQ 4
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 have several incoming transitions and no outgoing transitions, but an initial state has no incoming transitions and only one outgoing transition.
SAQ 4
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 might respond differently to the same message.
SAQ 5
What is the most common form of event that causes a transition between two states? How is it shown in a state machine 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 transition between the states. In a state machine diagram, a transition is labelled with the name of the relevant message, which includes any arguments for that message.
SAQ 5
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.
SAQ 5
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.
SAQ 5
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.
SAQ 5
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.
SAQ 6
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).
SAQ 7