lecture05 - Today COMPUTER SCIENCE 51 Spring 2009...

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

View Full Document Right Arrow Icon
2/17/2009 1 COMPUTER SCIENCE 51 Spring 2009 cs51.seas.harvard.edu Prof. Greg Morrisett Prof. Ramin Zabih Today How to enforce the abstraction barrier in PLT scheme. modules information hiding contracts Some simple abstract data types sets stacks queues Recall the Setup We have an abstract data type e.g., sets of integers We have a concrete implementation e.g., lists of integers coupled with an invariant: e.g., no duplicates We have a contract for clients: operations we guarantee to provide e.g., member? , insert , union , . .. promise about the semantics of operations e.g., (member? x (insert x s)) true The Intention We can change the implementation: e.g., use a binary tree instead of list e.g., use a different invariant (sorted, no duplicates) e.g., change to a different algorithm As long as we respect the contract. i.e., export at least the same operations i.e., with the same semantics Client code should be unaffected. except in good ways (e.g., runs faster). What Can Go Wrong? Clients may violate the contract may use an internal operation we didn’t mean to export (hidden APIs). may feed a concrete value to one of the operations that does not respect our invariants. e.g., a list with duplicates We may violate the contract e.g., violate the invariant e.g., change the observable semantics Example: Set Contract Our abstraction is a set of numbers . empty-set
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/26/2009 for the course COMPUTERSC CS51 taught by Professor Gregmorrisett during the Spring '09 term at Harvard.

Page1 / 5

lecture05 - Today COMPUTER SCIENCE 51 Spring 2009...

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

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