?? page108.html
字號:
<HTML>
<HEAD>
<TITLE>Abstract Data Types</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html3240" HREF="page109.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page109.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3238" HREF="page107.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page107.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3232" HREF="page107.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page107.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3242" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3243" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H1><A NAME="SECTION006100000000000000000">Abstract Data Types</A></H1>
<P>
A variable in a procedural programming language such as
Fortran<A NAME=4370> </A>, Pascal<A NAME=4371> </A>, C<A NAME=4372> </A>,
and C++<A NAME=4373> </A>,
is an abstraction.
The abstraction comprises a number of <em>attributes</em><A NAME=4375> </A>--name<A NAME=4376> </A>, address<A NAME=4377> </A>,
value<A NAME=4378> </A>, lifetime<A NAME=4379> </A>,
scope<A NAME=4380> </A>, type<A NAME=4381> </A>, and size<A NAME=4382> </A>.
Each attribute has an associated value.
E.g., if we declare an integer variable in C++, <tt>int x</tt>,
we say that the name attribute has value ``<tt>x</tt>''
and that the type attribute has value ``<tt>int</tt>''.
<P>
Unfortunately, the terminology can be somewhat confusing:
The word ``value'' has two different meanings--in one instance it denotes one of the attributes
and in the other it denotes the quantity assigned to an attribute.
E.g., after the assignment statement <tt>x = 5</tt>,
the <em>value attribute</em> has the <em>value</em> five.
<P>
The <em>name</em><A NAME=4390> </A> of a variable is the textual label
used to refer to that variable in the text of the source program.
The <em>address</em><A NAME=4392> </A> of a variable denotes
is location in memory.
The <em>value</em> attribute is the
quantity which that variable represents.<A NAME="tex2html185" HREF="footnode.html#5432" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/footnode.html#5432"><IMG ALIGN=BOTTOM ALT="gif" SRC="foot_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/foot_motif.gif"></A>
The <em>lifetime</em><A NAME=4406> </A> of a variable is the interval of time
during the execution of the program in which the variable is said to exist.
The <em>scope</em><A NAME=4408> </A> of a variable is the
set of statements in the text of the source program
in which the variable is said to be <em>visible</em><A NAME=4410> </A>.
The <em>type</em> of a variable denotes the set of values which
can be assigned to the <em>value</em> attribute
and the set of operations which can be performed on the variable.
Finally, the <em>size</em> attribute denotes the amount of storage
required to represent the variable.
<P>
The process of assigning a value to an attribute
is called <em>binding</em><A NAME=4415> </A>.
When a value is assigned to an attribute,
that attribute is said to be <em>bound</em><A NAME=4417> </A> to the value.
Depending on the semantics of the programming language,
and on the attribute in question,
the binding may be done statically by the compiler
or dynamically at run-time.
E.g., in C++ the <em>type</em> of a variable
is determined at compile time--<em>static binding</em><A NAME=4420> </A>.
On the other hand, the <em>value</em> of a variable is usually not
determined until run-time--<em>dynamic binding</em><A NAME=4423> </A>.
<P>
In this chapter we are concerned primarily with
the <em>type</em> attribute of a variable.
The type of a variable specifies two sets:
<UL><LI> a set of values; and,<LI> a set of operations.
</UL>
For example, when we declare a variable, say <tt>x</tt>, of type <tt>int</tt>,
we know that <tt>x</tt> can represent an integer
in the range <IMG WIDTH=96 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline61265" SRC="img674.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img674.gif" > (assuming 32-bit integers)
and that we can perform operations on <tt>x</tt>
such as addition, subtraction, multiplication, and division.
<P>
The type <tt>int</tt> is an <em>abstract data type</em><A NAME=4435> </A>
in the sense that we can think about the qualities of an <tt>int</tt>
apart from any real thing having that quality.
In other words, we don't need to know <em>how</em> <tt>int</tt>s are
represented nor how the operations are implemented
to be able to be able to use them or reason about them.
<P>
In designing <em>object-oriented</em><A NAME=4440> </A>
programs,
one of the primary concerns of the programmer is
to develop an appropriate collection of abstractions
for the application at hand,
and then to define suitable abstract data types
to represent those abstractions.
In so doing, the programmer must be conscious of the fact
that defining an abstract data type
requires the specification of <em>both</em>
a set of values and a set of operations on those values.
<P>
Indeed, it has been only since the advent of the so-called
<em>object-oriented programming languages</em><A NAME=4443> </A>
that the we see programming languages
which provide the necessary constructs to properly
declare abstract data types.
E.g., in C++, the <tt>class</tt> construct is the means
by which both a set of values and an associated set of operations is declared.
Compare this with the <tt>struct</tt> construct of C
or Pascal's <tt>record</tt><A NAME=4447> </A>,
which only allow the specification of a set of values!
<P>
<HR><A NAME="tex2html3240" HREF="page109.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page109.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3238" HREF="page107.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page107.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3232" HREF="page107.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page107.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3242" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3243" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright © 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.
</ADDRESS>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -