11+-+Abstract+Data+Types

11+-+Abstract+Data+Types - EECS 280 Programming and...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Abstract Data Types (ADTs) EECS 280 Programming and Introductory Data Structures 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Remembering Back Types Recall the role of a type: The set of values that can be represented by items of the type The set of operations that can be performed on items of the type. So far, we've discussed a variety of data types, and all of them have one thing in common: Every detail of a type is known to all consumers of that type. 2
Background image of page 2
Remembering Back Types For example, consider the struct Game from project 3. Every function knows the details of exactly how games are represented. A change to the game definition (for example, a more efficient encoding) requires that we recompile everything, and possibly make changes throughout the program. Contrast this with the functions that we've written. 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstract Data Types Introduction A function is given a specification which documents what the function does, but not how it does it. For example, if we find a faster way to compute factorial, we can just replace the old implementation with the new one, and no other component of the program needs to know this. This is a good thing, but so far, we can’t do that for types… 4
Background image of page 4
Abstract Data Types Introduction Abstract data types provide the following two advantages: 1. Information hiding : we don't need to know the details of how the object is represented , nor do we need to know how the operations on those objects are implemented . 2. Encapsulation : the objects and their operations are defined in the same place; the ADT combines both data and operation in one entity. 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstract Data Types Introduction Abstract data types have several benefits like we had with functional abstraction: ADTs are local : you only need to look at the ADT, and nothing else, to understand it. ADTs are substitutable : you can change the implementation and no users of the type can tell. Someone still needs to know the details of how the type is implemented. This is referred to as the “concrete representation” or just the “representation”. 6
Background image of page 6
Abstract Data Types Example The closest example of an ADT that we've seen so far has been a list_t : Information Hiding : In the list_t data type, you never knew the precise implementation of the list_t structure (except by looking in recursive.cpp ). Encapsulation : A list_t provides “modest” encapsulation. The definitions of the operations on lists ( list_print , list_make , etc.) were found in the same header file as the type definition of list_t , but there was no language mechanism that enforced this. 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstract Data Types On to Classes C++ provides a mechanism to give true encapsulation called a "class". The basic idea behind a class is to provide
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 51

11+-+Abstract+Data+Types - EECS 280 Programming and...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online