lec03 - CSE 12 ADT's, OOP, and Java ADT specifications and...

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

View Full Document Right Arrow Icon
03 ADT specifications and Programming by Contract Error handling with exceptions Test plans, test cases, and more about JUnit Generic programming and Java generic types CSE 12 ADT's, OOP, and Java
Background image of page 1

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

View Full DocumentRight Arrow Icon
Specifying an ADT An ADT specifies the possible values instances of the ADT can have, and specifies the operations the ADT provides on those values In more detail, an ADT specification should generally include these: ADT name: The name of the data type. ADT description: A brief summary description of the type. ADT invariants: Assertions that must always be true of any instance of this type. ADT attributes: Aspects of the state of an instance of the type, as observable by a client ADT operations: The behavior of an instance of the type, as observable by a client.
Background image of page 2
Specifying operations of an ADT Specifying ADT operations is particularly important: these operations constitute the API, and are the primary way that users of the ADT interact with its instances. For each ADT operation, you should specify: responsibilities : A brief summary of what the operation does. pre-conditions : What must be true on entry to the operation if the operation is to execute successfully. This may include assumptions about the state of the object, assumptions about the parameters passed in, etc. An operation's pre-conditions must be consistent with all of the ADT's invariants. post-conditions : What the operation guarantees to be true when it returns, if the pre-conditions were true when the operation was called. An operation's post-conditions must be consistent with all of the ADT’s invariants. returns : The value, if any, returned by the operation. exceptions : A description of the exceptions the operation may throw.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Programming by contract A precise and complete specification of an ADT operation is a contract for the operation It lays out the responsibilities of the provider (the method) and the client (any caller of the method) If both sides meets their responsibilities, the operation will work The contract is a guide both for the implementer and the users of the method Writing these specifications first, then implementing them, is sometimes called programming by contract
Background image of page 4
Pre- and Post-conditions Think of method pre conditions as the method saying: “I require this.” Think of method post conditions as the method saying: “I ensure this.” If the preconditions are satisfied when the method is called, then the method guarantees that the postconditions will be satisfied when the method returns. If the preconditions are not satisfied -- that is, if the client does not meet its end of the contract -- then the method does not guarantee anything!
Background image of page 5

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

View Full DocumentRight Arrow Icon
What is the relationship between class invariants and an operations pre - and post-conditions ? When a method is called, whose responsibility is
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2012 for the course CSE 12 taught by Professor Gary during the Fall '08 term at UCSD.

Page1 / 28

lec03 - CSE 12 ADT's, OOP, and Java ADT specifications and...

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

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