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, resulting in multiple receiving objects being active at the same time – leading to the possibility of non-deterministic behaviour.

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

How can conditional behaviour be shown on a sequence diagram?

A

By prefixing a message send with a guard that specifies the condition.

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

How can a repeated message send be shown on a sequence diagram?

A

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.

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

Does UML offer a more structured way of indicating conditional, alternative and iterative behaviour beyond the use of guards and branches?

A

Yes, there is a general notation known as a fragment or frame that can be used to show optional, alternative or looped behaviour.

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

Where does the responsibility for checking the precondition lie with defensive programming?

A

The checking of the precondition is done by the operation itself, that is, the receiver of the message.

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

Where does the responsibility for checking the precondition lie with design by contract?

A

The checking of the precondition is done by the caller of the operation, that is, the sender of the message.

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

What is the main disadvantage of defensive programming?

A

The main disadvantage of defensive programming is that the same constraints within each precondition may be checked repeatedly in different operations.

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

Describe the ‘one central class’ strategy for implementing use cases.

A

This is where the interface will send all messages to a single object. This central object will then forward messages to the appropriate object.

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

What are the advantages an disadvantages of the ‘one central class’ strategy?

A

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.

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

Describe the ‘actor classes’ strategy for implementing use cases.

A

This is where the interface will send a message to an object corresponding to the real-world actor who initiated the operation.

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

What is a disadvantage of the ‘actor classes’ strategy?

A

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

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

Describe the ‘use cases as classes’ strategy for implementing use cases.

A

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.

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

What are the advantages an disadvantages of the ‘use cases as classes’ strategy?

A

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.

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

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

What does a final state signify in a state machine?

A

Final states are used to show the point or points where the object in question has finished processing. Its activity has been completed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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 have several incoming transitions and no outgoing transitions, but an initial state has no incoming transitions and only one outgoing transition.

17
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 might respond differently to the same message.

18
Q

What is the most common form of event that causes a transition between two states? How is it shown in a state machine 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 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.

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

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

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

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

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

24
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 because the entry and exit events are not triggered.

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:

  • it is harder to write the eventual code for such classes because there are likely to be many conditional tests to identify the actual state
  • it is harder to test the classes because of the number of choices of pathway through the conditional tests
  • 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 these 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

The attribute returnDate is likely to change often, as it reflects the transition between the states on shelf and on loan and so is the most significant. Attributes such as libraryNumber and classification will only change as a result of some reorganisation within the library. 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 need 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

There are situations where 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 state machine diagrams to show how an object’s state would be affected.

28
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 a high or low temperature in a process-control system, to avoid problems or even disasters.
29
Q

UML lets us describe five things about a transition. What are they?

A

The five parts of a transition are:

  1. source state
  2. target state
  3. event trigger
  4. action (or action sequence)
  5. guard
30
Q

Do packages contain only 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.

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

32
Q

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

A

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

33
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 with their 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.

34
Q

Suppose you use «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.