Friday, June 28, 2013

KBP - Chapter 11

Review Question

1. Two kinds of abstractions in programming languages are process abstraction and data abstraction.

2. Define abstract data type.
An abstract data type is a data structure, in the form of a record, but which includes subprograms that manipulate its data.
Syntactically, an abstract data type is an enclosure that includes only the data representation of one specific data type and the subprograms that provide the operations for that type.

5. The first design issue for abstract data types is the form of the container for the interface to the type. The second design issue is whether abstract data types can be parameterized. The third design issue is what access controls are provided and how such controls are specified.

6. Explain how information hiding is provided in an Ada package.
There are two approaches to hiding the representation from clients in the package specification. One is to include two sections in the package specification—one in which entities are visible to clients and one that hides its contents.

9. Package specification, is an Ada package which provides the interface of the encapsulation (and perhaps more).
Body package, is an Ada package which provides the implementation of most, if not all, of the entities named in the associated package specification.

10. The ‘with’ clause in Ada makes the names defined in external packages visible.

15. The purpose of a C++ destructor is to deallocate heap space (memory) that the object or class used.

16. A destructor has no return types.

20. Limited private types are useful when the usual predefined operations of assignment and comparison are not meaningful or useful.

21. Intializers in Objective-C are constructors.

26. The purpose of a Destructor is usually to clear off unused variables and clean up the memory. Java has in built memory handling mechanisms (Garbage collection) that clear off unused memory automatically. Hence there is no requirement for destructor methods. So that Java doesn’t need any destructor

27. Methods in Java must be defined completely in a class.

28. Java classes are allocated from the heap and accessed through reference variables.

___________________________________________________
Problem Set

2. Suppose someone designed a stack abstract data type in which the function top returned an access path (or pointer ) rather than returning a copy of the top element. This is not a true data abstraction. Why ? Give an example that illustrates the problem.

- The problem with this is that the user is given access to the stack through the returned value of the “top” function. For example, if p is a pointer to objects of the type stored in the stack, we could have:

p = top(stack1);

*p = 42;

These statements access the stack directly, which violates the principle of a data abstraction.

4. The advantages of the nonpointer concept in Java?

• There is no memory leak such as dangling pointers or unnamed variables.

No comments:

Post a Comment