{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

designByContract - 2009 November 23 Design by Contract...

Info icon This 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
Image of page 1

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

View Full Document Right 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 : BOOLEAN insert ( x : INTEGER ) remove ( x : INTEGER ) member ( x : INTEGER ) : BOOLEAN 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 expressed in English.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern