0% found this document useful (0 votes)
11 views2 pages

01 Design Issues for Object- Oriented Languages

The document discusses the concept of abstract data types (ADTs) using a stack as an example, detailing operations such as create, destroy, empty, push, pop, and top. It emphasizes the importance of encapsulation, visibility, and the need for specific operations like iterators and accessors in the design of ADTs. Additionally, it mentions the support for ADTs in programming languages like C++, Java, and others, highlighting design considerations such as parameterization and access controls.

Uploaded by

prow8273
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

01 Design Issues for Object- Oriented Languages

The document discusses the concept of abstract data types (ADTs) using a stack as an example, detailing operations such as create, destroy, empty, push, pop, and top. It emphasizes the importance of encapsulation, visibility, and the need for specific operations like iterators and accessors in the design of ADTs. Additionally, it mentions the support for ADTs in programming languages like C++, Java, and others, highlighting design considerations such as parameterization and access controls.

Uploaded by

prow8273
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

476 Chapter 11 Abstract Data Types and Encapsulation Constructs

11.2.3 An Example
A stack is a widely applicable data structure that stores some number of data
elements and only allows access to the data element at one of its ends, the top.
Suppose an abstract data type is to be constructed for a stack that has the fol-
lowing abstract operations:

create(stack) Creates and possibly initializes a stack object


destroy(stack) Deallocates the storage for the stack
empty(stack) A predicate (or Boolean) function that returns true
if the specified stack is empty and false otherwise
push(stack, element) Pushes the specified element on the specified stack
pop(stack) Removes the top element from the specified stack
top(stack) Returns a copy of the top element from the speci-
fied stack

Note that some implementations of abstract data types do not require the
create and destroy operations. For example, simply defining a variable to be of
an abstract data type may implicitly create the underlying data structure and
initialize it. The storage for such a variable may be implicitly deallocated at the
end of the variable’s scope.
A client of the stack type could have a code sequence such as the following:

. . .
create(stk1);
push(stk1, color1);
push(stk1, color2);
temp = top(stk1);
. . .

11.3 Design Issues for Abstract Data Types


A facility for defining abstract data types in a language must provide a syn-
tactic unit that encloses the declaration of the type and the prototypes of the
subprograms that implement the operations on objects of the type. It must be
possible to make these visible to clients of the abstraction. This allows clients
to declare variables of the abstract type and manipulate their values. Although
the type name must have external visibility, the type representation must be
hidden. The type representation and the definitions of the subprograms that
implement the operations may appear inside or outside this syntactic unit.
Few, if any, general built-in operations should be provided for objects of
abstract data types, other than those provided with the type definition. There
simply are not many operations that apply to a broad range of abstract data
11.4 Language Examples 477

types. Among these are assignment and comparisons for equality and inequality.
If the language does not allow users to overload assignment, the assignment
operation must be included in the abstraction. Comparisons for equality and
inequality should be predefined in the abstraction in some cases but not in
others. For example, if the type is implemented as a pointer, equality may mean
pointer equality, but the designer may want it to mean equality of the structures
referenced by the pointers.
Some operations are required by many abstract data types, but because
they are not universal, they often must be provided by the designer of the type.
Among these are iterators, accessors, constructors, and destructors. Iterators
were discussed in Chapter 8. Accessors provide a form of access to data that is
hidden from direct access by clients. Constructors are used to initialize parts of
newly created objects. Destructors are often used to reclaim heap storage that
may be used by parts of abstract data type objects in languages that do not do
implicit storage reclamation.
As stated earlier, the enclosure for an abstract data type defines a single
data type and its operations. Many contemporary languages, including C++,
Objective-C, Java, and C#, directly support abstract data types.
The first design issue is whether abstract data types can be parameterized.
For example, if the language supports parameterized abstract data types, one
could design an abstract data type for some structure that could store elements
of any type. Parameterized abstract data types are discussed in Section 11.5.
The second design issue is what access controls are provided and how such
controls are specified. Finally, the language designer must decide whether the
specification of the type is physically separate from its implementation (or
whether that is a developer choice).

11.4 Language Examples


The concept of data abstraction had its origins in SIMULA 67, although that
language did not provide complete support for abstract data types, because it did
not include a way to hide implementation details. In this section, we describe the
support for data abstraction provided by C++, Objective-C, Java, C#, and Ruby.

11.4.1 Abstract Data Types in C++


C++, which was first released in 1985, was created by adding features to C. The
first important additions were those to support object-oriented programming.
Because one of the primary components of object-oriented programming is
abstract data types, C++ obviously is required to support them.
C++ provides two constructs that are very similar to each other, the class
and the struct, which more directly support abstract data types. Because structs
are most commonly used when only data is included, we do not discuss them
further here.

You might also like