Unit 6 Flashcards
In the analysis and design phases of system development that you studied in Units 3 and 5, what were the assertions (preconditions, postconditions and invariants) used for?
Assertions were used for placing constraints on the relationships between classes.
What is meant by the term Design by Contract (DbC)?
DbC is the process of developing software based on the notion of a contract between objects.
Explain why pre-and postconditions express a contract between a client object and a supplier object.
The contract is expressed by:
- the precondition requiring something from the client object, which is of benefit to the supplier object;
- the postcondition requiring something from the supplier object, which is of benefit to the client object.
What is the important feature of DbC, which shows that it can be used to improve the quality of a software system?
DbC allows the development of a software system to be traced from requirements through to code.
What is the relationship between the client’s and supplier’s obligations and benefits?
A client’s obligations to constrain inputs provide benefits to a supplier in that not so many 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.
What does weakening a precondition mean in terms of the provision of a service?
To weaken 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.
Similarly, what does strengthening a postcondition mean?
To strengthen 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.
Under what circumstances is one object, obj1 of class A, say, substitutable for another, obj2 of class B, say?
Class A must be a subclass of class B, and class A must respect all contracts agreed to by class B.
What three sets of items should you examine to help you find suitable postconditions when identifying the possible operations for a class?
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.
Figure 1 shows 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.
The contract between the library member and the library to borrow a book is constrained as follows.
Precondition:
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 real-world 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.
Postcondition:
a new instance of the class Loan will have been created;
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.
What is the difference in emphasis between sequence diagrams and communication diagrams?
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.
How is time represented in a communication diagram?
Time is represented by the sequential numbering of messages (see Section 4).
What obligation is placed on an object that is sent a message?
The class of the receiving object is committed to implement an operation with a particular name and argument signature.
How does the use of a pair of object diagrams help you prepare to build a sequence diagram?
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.
Is the initial message on an interaction diagram always sent from an object representing the user interface?
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. However, interaction diagrams can become very complex if we try to show all the possible messages for a given configuration of objects. Following the principle of modularisation, we would split up a complex interaction into a number of smaller ones. In the new diagrams, the starting point need not be the user interface.