It's about life

Chapter 11

Abstract Data Types and Encapsulation Constructs

Assignment from Tri Djoko Wahjono

Review Questions

1. What are the two kinds of abstractions in programming languages?
Process abstraction and data abstraction.

2. Define abstract data type.
An abstract data type is a user-defined data type that satisfies the following two conditions:
– The representation of, and operations on, objects of the type are defined in a single syntactic unit
– The representation of objects of the type is hidden from the program units that use these objects, so the only operations possible are those provided in the type’s definition

3. What are the advantages of the two parts of the definition of abstract data type?
– Advantage of the first condition
Program organization, modifiability (everything associated with a data structure is together), and separate compilation

– Advantage the second condition
Reliability–by hiding the data representations, user code cannot directly access objects of the type or depend on the representation, allowing the representation to be changed without affecting user code

4. What are the language design requirements for a language that supports abstract data types?
A syntactic unit in which to encapsulate the type definition. A method of making type names and subprogram headers visible to clients, while hiding actual definitions. Some primitive operations must be built into the language processor.

5. What are the language design issues for abstract data types?
What is the form of the container for the interface to the type?
Can abstract types be parameterized?
What access controls are provided?

6. Explain how information hiding is provided in an Ada package.
– The spec package has two parts, public and private
– The name of the abstract type appears in the public part of the specification package. This part may also include representations of unhidden types
– The representation of the abstract type appears in a part of the specification called the private part

7. To what is the private part of an Ada package specification visible?
Public part

8. What is the difference between private and limited private types in Ada?
Private types have built-in operations for assignment and comparison. Limited private types have NO built-in operations

10. What is the use of the Ada with clause?
Visibility from a program unit is gained with the with clause

11. What is the use of the Ada use clause?
The use clause eliminates the need for explicit qualification of the references to entities from the named package.

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. What are the advantages of the nonpointer concept in Java?
– Variable Access are absolutely defined by the programmer
– No memory leak (i.e. dangling pointers, nameless variables etc)

9. What happens if the constructor is absent in Java and C++?
The compiler will automatically make a default one

11. Why is the destructor of C# rarely used?
Because C# has its own garbage collection method, just like Java


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


This entry was posted on June 28, 2013 by and tagged .
June 2013
« Apr   Sep »

Blog Stats

  • 10,673 hits
%d bloggers like this: