Unit 6 - Dynamic Modelling - from analysis to design Flashcards

1
Q

Preconditions, postconditions and invariants are collectively known as?

A

Assertions - which are statements that are, in theory

at least, either true or false.

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

What are the four main advantages to the DbC approach for adding assertions:

A

1 Assertions provide accurate documentation for the implemented classes so that a programmer knows how to use the classes and what to expect from them.

2 Provided that they are executable, assertions are an important aid to testing, but without being an obstacle to efficiency.

3 Assertions provide a way of controlling inheritance in which substitutability and redefinition of methods are allowed.

4 Provided that the programming language has an exception mechanism that accords with the principles of DbC, assertions together with the exception-handling mechanism can be an important aid to developing mission-critical systems.

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

In the analysis phase of system development that you studied in Units 3 and 5, what were the assertions (preconditions, postconditions and invariants) used for?

A

Assertions were used for placing constraints on the relationships between classes.

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

Explain why pre- and postconditions express a contract between a client object and a supplier object.

A

The contract is expressed by:

◦ the precondition requiring something from the client object that is of benefit to the supplier object

◦ the postcondition requiring something from the supplier object that is of benefit to the client object.

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

What is meant by the term design by contract (DbC)?

A

DbC is the process of developing software based on the notion of a contract between objects.

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

To what extent can DbC help with traceability, and hence be used to improve the quality of a software system?

A

DbC allows the development of a software system to be traced from requirements through to code.

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

What is the relationship between the client’s and supplier’s obligations and benefits?

A

A client’s obligations to constrain inputs provide benefits to a supplier in that fewer input cases need to be considered. A supplier’s obligations to produce outputs satisfying certain constraints mean that a client can expect to receive a clearly defined service.

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

What does weakening a precondition mean in terms of the provision of a service?

A

Weakening a precondition means generalising the situation in which a service can be provided. In general, this means that it is easier for the client to satisfy the precondition because there are ‘fewer’
conditions to be satisfied.

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

Similarly, what does strengthening a postcondition mean?

A

Strengthening a postcondition means making the service that is requested ‘better’ in terms of time, precision or some other measurable item.

The precise notion of ‘better’ is not fixed, but must
be considered in terms of the contract of which the postcondition is part. It can, however, make the postcondition more difficult for the supplier to satisfy because there are ‘more’ conditions to be satisfied.

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

Under what circumstances is one object, obj1 of class A, say, substitutable for another, obj2 of class B, say?

A

Class A must be a subclass of class B, and class A must respect all contracts agreed to by class B.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Once a class model that meets the contractual requirements of each use case has been developed, what three sets of items in this class model should you examine to help you find suitable postconditions
when identifying the possible operations for a class?
A

You should investigate the following three sets of items when searching for the possible postconditions for an operation:
◦ instances of a class (its objects) that have been created or deleted
◦ instances of associations (links) that have been formed or broken
◦ attributes that have been modified.

It is crucial of course that the postconditions reflect the requirements, and some practitioners would refer more directly to the requirements.

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

Think of a class model for the lending of books where there is a requirement to record both past and current loans.

Describe the contract to borrow a book in terms of objects and links created. Your answer should differentiate between the pre- and the postconditions.

A

The contract between the library member and the library to borrow a book is constrained as follows.

Preconditions:
there must be an instance of the class LibraryMember that corresponds to the real-world member

there must be an instance of the class Book that corresponds to the realworld book that the member wants to borrow

the instance of the class LibraryMember must be linked to fewer than 3 instances of the class Loan in the role of currentLoans.

Postconditions:
a new instance of the class Loan will have been created and the instance of the class LibraryMember will have been linked to the new instance of
Loan in the role of currentLoans

the instance of the class Book will have been linked to the same new instance of the class Loan.

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

How does the use of a pair of object diagrams help you prepare to build a sequence diagram?

A

The aim is to show how a given postcondition can be achieved in a sequence diagram. A pair of object diagrams, showing the states before and after the operation in question, identifies the changes in
system state that take place in order to meet the postcondition

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

Is the initial message on an interaction diagram always sent from an object representing the user interface?

A

No – we are not constrained to showing interactions with the user interface. Message sequences can originate from any object. The user interface is the origin for those messages that relate to a use case
scenario, which we have described in the case of checking guests in to a hotel.

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

What is GRASP an acronym for?

A

general responsibility assignment software patterns

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

What does the GRASP expert address?

A

The problem of distributing responsibilities for knowing across the system, in particular for information that should be derived from object properties.

The fulfilment of a responsibility within a system often requires the consolidation of information that is distributed among several different objects, each being
knowledgeable or being an ‘expert’ on some aspect of such information. The Expert pattern allows you to distribute responsibilities among ‘information
experts’ in a way that encourages cohesive class definitions, which are easier to understand and maintain.

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

What is the intent of the GRASP Expert?

A

To assign responsibility based on object properties.

The responsibility is assigned to the class that has the
information necessary to fulfil that responsibility – the ‘information expert’; this information is represented by the properties of the object of the class.

Use this pattern when you need to decide which of a number of interacting objects a responsibility should be assigned to.

18
Q

What does the GRASP creator do?

A

The GRASP Creator pattern is used to assign
responsibilities related to the creation of objects. Its objective is to find a creator that needs to be linked to the created object, because the creator aggregates, maintains or records, or contains the created object.

19
Q

What is the intent of the GRASP Creator?

A

To assign responsibility for creating objects.

The responsibility for creating an instance of some class is assigned to the class that aggregates, maintains or records, or contains instances of the class of the newly created object, especially if the creator
class provides the data required to initialise the newly created object.
Use this pattern whenever you need to assign responsibilities for object creation. Low coupling is maintained between the creator class and
the class of the created object, because the latter is probably already linked to the creator class owing to the existing associations that motivated its choice
as the creator.
20
Q

In an interaction diagram, which class must provide the operation indicated by a message passed from one object to another?

A

The class of the receiver object must provide the appropriate operation.

21
Q

What does a lifeline represent?

A

A lifeline represents the portion of the life of an object covered by the sequence diagram.

22
Q

What does the box at the top of a lifeline include?

A
It includes an instance name, optionally followed by a colon and a class name, or, for a generic object, just a colon and a class name.
For example, objectname, objectName : ClassName and : Classname are all allowed.
23
Q

What sort of arrowhead is used on an arrow depicting synchronous message sending?

A

A solid black arrowhead, which indicates that the interaction is procedural. An arrowhead with a dashed shaft is used to signify the method’s return, although it is often omitted for clarity.

24
Q

What is a procedural interaction? With what might it be contrasted?

A

It is an interaction in which the sender of a message is blocked until the receiver of the message has finished processing. This is exactly the same as what is sometimes called subroutine semantics. It is the
usual policy when a single thread of control is allowed. If multiple threads are allowed, we might not want the sender of the message to block, in which case we could start a concurrent activity

25
Q

In a sequence diagram, what does the widening of a lifeline into a tall, thin rectangle mean?

A

This shows that the object is active. An object is said to be active if it is either performing an operation or awaiting completion of an operation that it has requested another object to perform.

26
Q

What does to delegate mean in the context of object-oriented design?

A

One object is said to delegate behaviour to another when, instead of implementing some behaviour, it sends a message to another object that implements that behaviour. We considered the possibility that instead of the Hotel doing all the work of finding a free room and
housing jill in it, the Hotel might delegate the work to a Room by passing it the message attemptToAccommodate(jill).

27
Q

Would you describe a sequence diagram as a programming notation?

A

Not really, because all it shows is the inter-object message traffic. It does not represent the algorithms needed by senders in order to decide when and to which objects messages should be sent, or those
needed by receivers in order to act on the messages.

When you have finished drawing sequence diagrams you know the interfaces of the various classes but not how those interfaces will be implemented.

28
Q

What are the two main differences between

communication diagrams and sequence diagrams?

A

A communication diagram shows in one place all the links of interest between objects, whereas a sequence diagram does not. You can see the messages flowing along the links in. In a sequence diagram you must scan down the diagram to find which links are being used.

The time-ordering of messages is clear in a sequence diagram; time passes by as you travel down the page. Some form of numbering is needed in a communication diagram to show the time-ordering of
messages, and the numbering can become very complicated.

29
Q

How is the sequencing of messages represented in a communication diagram?

A

Every message has a multi-stage number. The numbers specify the sequencing, replacing vertical position in a sequence diagram.

30
Q

Sequence diagrams and communication diagrams show almost equivalent information. What are their respective strengths and weaknesses?

A

Sequence diagrams make the relative order of messages extremely easy to see by presenting time vertically. Communication diagrams are an extension of object diagrams, so there is less new notation.
They make it easy to see the links and to show role names, at the cost of making the relative ordering of messages less immediately clear.

31
Q

What is the difference in emphasis between sequence diagrams and communication diagrams?

A

Sequence diagrams emphasise the flow of messages from object to object over time.

Communication diagrams emphasise the message traffic across the links in a particular configuration of objects.

32
Q

How is time represented in a communication diagram?

A

Time is represented by the sequential numbering of messages.

33
Q

What obligation is placed on an object that is sent a message?

A

The class of the receiving object is committed to implement an operation with a particular name and parameter signature.

34
Q

How does an assignment statement help construct a prototypical sequence diagram?

A

In a programming language, an assignment statement allows you to store the result of one message in a variable and then send messages to whatever
object is currently referenced by that variable.

You can use the same mechanism in UML, although the name used to store the message result is not the same as a programming variable.

35
Q

How does a sequence diagram drawn for a use case scenario differ from one drawn to show how an internal operation, such as findAFreeRoom in Figure 14, is carried out?

A

A sequence diagram of a use case scenario will always have the very first message originating from an object which has been stimulated, directly or indirectly, by an actor (usually a user interface object).

An internal operation will be invoked by a message that has been identified in the use case scenario. You can show how the recipient of that message achieves the required behaviour, for example how a free room is found. In all other respects they are the same

36
Q

Would you expect to use sequence diagrams in a conceptual model?

A

Sequence diagrams are about message passing between software objects and conceptual models are about things in the world, where the language of message passing makes no sense.

37
Q

What are the advantages of recognising when an association is unidirectional?

A

Specifying an association in just one direction simplifies the implementation of the classes at each end and avoids the need to worry that both ends of
the link are consistent when dealing with instances of those classes. But be aware that the overall flexibility is reduced in comparison with bidirectional
associations.

38
Q

Suppose that, in a Java implementation, a Company class represents the employment association with the Person class as a Vector of Person objects. What would be the disadvantage of providing a method Company::getAllEmployees that returned the Vector?

A
If Company::getAllEmployees is defined as returning an instance of the class Vector, changing the internal representation creates either a maintenance problem or a data-type conversion problem. Suppose the
internal representation is changed to be an array. You then have to decide whether getAllEmployees should be changed to return the array (affecting all existing clients of the class) or a new Vector should be
constructed from the array.
39
Q

What is the Law of Demeter?

A

It states states that a method m in a class A should not send a message to another object unless that object is one of the following:

. an instance variable used in the method m
. a parameter to the method m
. an object created in the method m
. a global variable (the nearest thing to this in Java is a public static variable) used in the method m.

40
Q

According to the Law of Demeter, an object should send messages only to a certain set of objects including the object itself. List the other objects.

A

The Law of Demeter allows an object to send messages to:

◦ any objects communicated as parameters of the current method
◦ any new objects that the object has created in the current method
◦ any objects to which the object has direct links – its
neighbours
◦ itself.

41
Q

In Figure 25 which pattern would be outlawed by the Law of Demeter?

A

The fork pattern would be outlawed. Here it would involve sending a message to the Job to get a Person, and then sending messages to the resultant Person object.

The law bans the sending of messages
to objects that are returned as a result of sending other messages.

The cascade implementation involves the Company talking only to Job, and Job talking only to Person. Both of these are direct associations, so the Law of Demeter will allow this.

One advantage of using the cascade pattern is that the Company is independent of how the age of an employee is represented. You could store the age directly within Job, or you could store it in an associated Person object. The Company will be oblivious to such choices.