CS 12 Assignment 3, part 1, Fall 2008 Adapted/extended from textbook's solutions package by cmc, 10/24/08 4.5 Review Questions 2, 3, and 4 2. Information hiding occurs when program entities are declared and used locally within a function or module, preventing them from being seen and/or used outside the function or module. 3. Information hiding can promote ease of program modification by confining the region of program text in which changes have to be made to a local region of the total program text. When entities are defined locally within a function, or privately inside a module in its implementation file, then changes in the local or private entities can be made without interfering with entities outside. 4. A representation-independent notation is a notation which does not have to be changed when its underlying data representation is changed. For example, GetLink(N) is a representation-independent notation for getting the Link of node N in a linked-list, whereas the three expressions N->Link, ListMemory[N].Link, and Link[N] are representation-dependent notations (from which, by looking at the notations, one can discover what the underlying data representations are). 4.6 Review Questions 2, and 3 2. Procedural abstraction occurs when one creates a procedure, P( a1, a2, ..., an), as a named unit of action. Then, one can use the action represented by P, knowing only what P does and not how P is implemented. Later, one can change how P is implemented without changing every instance of P's use (which could not have happened if the instructions giving P's action had been repeated every time P was used). The use of procedural abstraction therefore promotes ease of use and change. 3. Data abstraction occurs when one hides the representation of a data structure and the implementation details of the operations on it using a representation-independent notation. This enables the abstract data to be used knowing only what it does, not how its details are implemented. As with procedural abstraction, so also with data abstraction, by separating the what from the how, both ease of use and ease of modification are promoted. 5.3 Review Questions 1, 2, and 3 1. Assertions are logical statements that specify conditions that must be true. Especially (not necessary for full credit) { (a) the conditions that hold before a program is executed, (b) the net effect achieved after executing a program, or (c) the state of affairs achieved inside a program at various intermediate points during its execution. } 2. The precondition describes the conditions that hold true before a program (or function) is executed. 3. The postcondition describes the conditions that hold true after a program (or function) is executed. 5.5 Review Question 1 Unit testing consists of testing individual functions in isolation to see if they work on all expected classes of inputs. Integration testing tests the coordinated execution of functions, acting together in the context of the conditions expected for actual system operations.