designByContract - 2009 November 23 Design by Contract...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
2009 November 23 Design by Contract Example Test Questions 1. Explain when and why one can use Design by Contract. Explain when and why one cannot use Design by Contract. 2. A State and explain the correctness rule for a class with respect to its assertions for a creation routine. B State and explain the formal correctness rule for a class with respect to its assertions for exported routines. C State and explain the formal correctness rule for retry inducing rescue clauses (does a retry). D State and explain the formal correctness rule for failure inducing rescue clauses (doesn’t do a retry). 3. Describe the benefits and obligations of the client and supplier when using design by contract. 4. In the context of software environment define the term exception. Does every exception lead to a routine failure? Justify your answer. Discuss the two legitimate responses to an exception. Justify your answers. 5. A What is defensive programming? B Explain why defensive programming is a poor method. C Defensive programming suggests the following programming style. remove (object) is require size > 0 if size < 1 then throw exception else ... rest of procedure . .. end remove Using example pseudocode from the client side, show why defensive programming is futile, if the client is a good programmer. 6. Given following two classes: class B feature x : INTEGER; y : INTEGER do_work ( a : INTEGER ) is require alpha: a < 0 ensure beta: x >= a + 20 and y < old y + x end class C feature inherit B redefine do_work end do_work ( a : INTEGER ) is require gamma: a <= 0 ensure delta: x >= 21 + a and y – old y - 20 < a end
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2009 November 23 Design by Contract Example Test Questions Page 2 of 11 end end Assume we have an Eiffel compiler that does not enforce the Assertion Redeclaration Rule. We therefore need to use our knowledge of mathematics and logic to verify the subcontracting by class C eliminates the possibility of cheating. State what needs to be proved and prove it. 7. Let A and B be two classes related as shown by the following BON diagram. In order to prevent cheating, the redeclaration of the assertions in an heir must follow the "Assertion Redeclaration Rule". Give a definition for this rule. Using references to feature r of class B , explain this rule. 8. The following figure shows a simple class interface for a class MY_SET that holds only integers. The elements of the set are represented as an ARRAY of integers. MY_SET MY-SET contents : ARRAY[INTEGER] is_empty : BOOLEAN is_full : insert ( x : INTEGER ) remove ( ) member ( x : INTEGER ) : union ( s : MY_SET ) Give require and ensure clauses for each of the set features. Write your contracts as formally as possible. You can use any features of ARRAY that you like in your contracts; if you are unsure as to which features ARRAY possesses, clearly state your assumptions. You may use BON assertion language. Answers expressed in mathematics receive significantly higher grades than answers
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/11/2010 for the course CSE CSE 3311 taught by Professor A during the Winter '10 term at York University.

Page1 / 11

designByContract - 2009 November 23 Design by Contract...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online