Unit 6 Flashcards
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.
In terms of DbC, what is meant by an assertion?
In DbC, an assertion is a precondition, a postcondition or an invariant.
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 that is of benefit to the supplier object
- the postcondition requiring something from the supplier object that is of benefit to the client object.
What are the main advantages of the DbC approach for adding assertions?
- Assertions provide accurate documentation for the implemented classes so that a programmer knows how to use the classes and what to expect from them.
- Provided that they are executable, assertions are an important aid to testing, but without being an obstacle to efficiency.
- Assertions provide a way of controlling inheritance in which substitutability and redefinition of methods are allowed.
- 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.
To what extent can DbC help with traceability, and hence 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 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.
What does weakening a precondition mean in terms of the provision of a service?
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.
What does strengthening a postcondition mean in terms of the provision of a service?
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.
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.
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?
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 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.
What does the acronym, GRASP, stand for?
General responsibility assignment software patterns.
How does the GRASP Expert pattern work?
This pattern assigns the responsibility in a system to a class that has the information necessary to fulfill that responsibility. This information is represented by the properties of the object of the class.
When would you use the GRASP Expert pattern?
This pattern should be used when you need to decide which of a number of interacting objects a responsibility.