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, resulting in multiple receiving objects being active at the same time – leading to the possibility of non-deterministic behaviour.
How can conditional behaviour be shown on a sequence diagram?
By prefixing a message send with a guard that specifies the condition.
How can a repeated message send be shown on a sequence diagram?
UML uses the * notation for a repeated message send, which may be attached to a guard. For example, *[i := 1..10] would be used to one message ten times.
Does UML offer a more structured way of indicating conditional, alternative and iterative behaviour beyond the use of guards and branches?
Yes, there is a general notation known as a fragment or frame that can be used to show optional, alternative or looped behaviour.
Where does the responsibility for checking the precondition lie with defensive programming?
The checking of the precondition is done by the operation itself, that is, the receiver of the message.
Where does the responsibility for checking the precondition lie with design by contract?
The checking of the precondition is done by the caller of the operation, that is, the sender of the message.
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.
Describe the ‘one central class’ strategy for implementing use cases.
This is where the interface will send all messages to a single object. This central object will then forward messages to the appropriate object.
What are the advantages an disadvantages of the ‘one central class’ strategy?
From the interface’s point of view, it has to know the existence of only one object. There is good traceability from use cases to code because every use case links to a method in the same central class.
The main disadvantage arises when the one central class becomes overloaded with use cases. One possible solution to this problem is to divide the software system into several packages. Each package could still make use of one class to respond to messages from the interface. The focus of each package would be on the key concepts within each domain.
Describe the ‘actor classes’ strategy for implementing use cases.
This is where the interface will send a message to an object corresponding to the real-world actor who initiated the operation.
What is a disadvantage of the ‘actor classes’ strategy?
Traceability is rather different from that for one central class. To locate the code for a use case, the class corresponding to the initiating actor must be searched. There is a complication when there are two actors that can initiate an interaction
Describe the ‘use cases as classes’ strategy for implementing use cases.
This is where the interface messages are sent to a object of a class that has been specifically defined for the use case. There might be classes such as CheckerIn, CheckerOut and ReservationMaker. Each would have a method with a name like run, with a suitable number of arguments. The user interface would then create a single instance of the appropriate class, initialise it suitably and then send the run(…) message.
What are the advantages an disadvantages of the ‘use cases as classes’ strategy?
Working with use case objects lets you change or even replace the software to implement a given scenario, minimising the effects upon the core concepts.
Advocates of such use case objects appreciate the traceability they provide from each use case to a class. Each use case class contains information relevant to the use case alone, so each use case can be understood in isolation. If you want to collect management information about the use case, such as frequency of use or timing histories, having an object provides a natural place to put such functionality.
A possible disadvantage of the approach is the large number of extra classes that must be defined – one for each use case.
Another possible disadvantage is that many of the use case classes can be similar, resulting in duplicated code and more difficult maintenance.
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 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.