12.07.2015 Views

Chapter 4 Data Abstraction: The Walls Abstract Data Types Abstract ...

Chapter 4 Data Abstraction: The Walls Abstract Data Types Abstract ...

Chapter 4 Data Abstraction: The Walls Abstract Data Types Abstract ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Chapter</strong> 4<strong>Abstract</strong> <strong>Data</strong> <strong>Types</strong><strong>Data</strong> <strong><strong>Abstract</strong>ion</strong>: <strong>The</strong> <strong>Walls</strong>Figure 4-1Isolated tasks: the implementation of task T does not affect task Q© 2006 Pearson Addison-Wesley. All rights reserved 4-1© 2006 Pearson Addison-Wesley. All rights reserved 4-2<strong>Abstract</strong> <strong>Data</strong> <strong>Types</strong>• <strong>The</strong> isolation of modules is not total– Methods’ specifications, or contracts, govern how they interactwith each other<strong>Abstract</strong> <strong>Data</strong> <strong>Types</strong>• <strong>Abstract</strong> data type (ADT)– An ADT is composed of• A collection of data• A set of operations on that data– Specifications of an ADT indicate• What the ADT operations do, not how to implementthem– Implementation of an ADT• Includes choosing a particular data structureFigure 4-2A slit in the wall© 2006 Pearson Addison-Wesley. All rights reserved 4-3© 2006 Pearson Addison-Wesley. All rights reserved 4-4<strong>Abstract</strong> <strong>Data</strong> <strong>Types</strong><strong>Abstract</strong> <strong>Data</strong> <strong>Types</strong>• <strong>Data</strong> structure– A construct that is defined within a programminglanguage to store a collection of data– Example: arrays• ADTs and data structures are not the same• <strong>Data</strong> abstraction– Results in a wall of ADT operations between datastructures and the program that accesses the data withinthese data structures© 2006 Pearson Addison-Wesley. All rights reserved 4-5Figure 4-4A wall of ADT operations isolates a data structure from the program that uses it© 2006 Pearson Addison-Wesley. All rights reserved 4-6


Specifying ADTsImplementing ADTs• In a list– Except for the first and lastitems, each item has• A unique predecessor• A unique successor– Head or front• Does not have a predecessor– Tail or end• Does not have a successorFigure 4-5A grocery list© 2006 Pearson Addison-Wesley. All rights reserved 4-7Figure 4-8ADT operations provide access to a data structure© 2006 Pearson Addison-Wesley. All rights reserved 4-8Implementing ADTsJava Classes RevisitedFigure 4-10An object’s data andmethods are encapsulatedFigure 4-9Violating the wall of ADT operations© 2006 Pearson Addison-Wesley. All rights reserved 4-9© 2006 Pearson Addison-Wesley. All rights reserved 4-10An Array-Based Implementationof the ADT ListAn Array-Based Implementationof the ADT List• An array-based implementation– A list’s items are stored in an array items– A natural choice• Both an array and a list identify their items bynumber– A list’s k th item will be stored in items[k-1]Figure 4-11An array-based implementation of the ADT list© 2006 Pearson Addison-Wesley. All rights reserved 4-11© 2006 Pearson Addison-Wesley. All rights reserved 4-12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!