CS 541 Lecture -*-Outline-*- * Encapsultion (Ch. 6) programming in the large -- building large programs from modules Q: what are characteristicsof quality in a module? single purpose narrow interface Q: what is an interface? clearly documented and specified Q: What separates spec from implementation? info hiding thinking at the right level def: modules -- procs or groups of related declarations aka package ** packages *** simple packages (6.1.1) Q: how is a package like a record? how is it not? how is it like an environment? *** information hiding (6.1.2) a package has both exported and hidden parts Q: How are the exported and hidden parts of an Ada package distinguished? Q: How can block decls be used to achieve information hiding? in ML there is another way too: use of signatures ** ADTs (6.2) Explain some of the history of this concept Q: what problems can occur when we represent one type by another? rep type can have extra values (junk) rep type may have more than one rep for values of the desired type (non-minimal) incorrect rep type may have only one rep value for each a single value of the desired type (confusion) talk about example 6.6 on page 111 Q: how do ADTs help in writing programs? Q: In what sense is a spec necessary for ADTs? talk about client, etc. Q: How do ADTs help in thinking and reasoning about programs? Q: How can you define the expressive power (convenience) of an ADT? ** Objects and Classes (6.3) *** Single objects (6.3.1) An object is a single variable, hidden in a module, with interface some operations Can think of it as an abstraction of a resource (e.g., a printer) Need to internalize the variable (see stmt on p.114) *** Object Classes (6.3.2) A class is a module that can be used to create many objects, all of which understand the same protocol (more or less) Q: How is a class different than an ADT? - notation (not a big deal) - Objects are updateable, but you can imagine non-updateable objects - In what way are ADTs more like built-in types (other than notation)? They are first class, but OO languages can do this. - A major difference is that usually one only has 1 implementation of an ADT in a program but can have many similar classes, whose objects can all be thought of as having the same type. ** generics (6.4) *** generic abstractions (6.4.1) a generic abstraction is a parameterized declaration queues and stacks, numbers modulo some prime e.g., generic packages in Ada functors in SML *** type parameters - the most useful kind of generic parameter e.g., queue of T Q: how are type parameters different from value parameters? What is the "type" of a type parameter? need to know how to work with it. go over top of p. 122 carefully They may also depend on each other see example 6.13 Q: What happens if you allow types as parameters to functions or procedures?