Lecture10-ADT-intro - Last time: * exceptions Next few...

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

View Full Document Right Arrow Icon
Last time: * exceptions Next few lectures: * Abstract Data Types * Two advantages * A simple example * A more realistic example: IntSet * Initializing objects: constructors * Modifying representations: the advantages of ADTs +++++++++++++++++++++++++++++++++++++++++++++++++ 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---this is sometimes called the "concrete implementation". For example, consider the struct game_t from project three. * 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. 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. To solve this problem, we'll define abstract data types, or ADTs. An ADT provides an *abstract* description of values and operations. Thus, the definition of an ADT must combine *both* some notion of *what* values of that type represent, and *how* they behave. However, we can leave off the details of how this actually happens. Abstract data types provide the following two advantages: * information hiding: we don't need to know the details of *how* the object is represented, nor do we need to know the operations on those objects are implemented. * encapsulation: the objects and their operations are defined in the same place; the ADT combines both data and operation in one entity. This gives us the same benefits that we had with functional
Background image of page 1

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

View Full DocumentRight Arrow Icon
abstraction, namely ADTs are local (you only need to look at the ADT to understand it) and substitutable (you can change the implementation and no users of the type can tell.) Of course, someone needs to know the details of how the type is implemented---we refer to this as the "concrete representation", or sometimes just the "representation." However, we want to make sure that *only* the operations defined for that type have access to the representation. Everyone else may access/modify this state only through member functions. 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, unless you went to the trouble of looking at recursive.cpp. Encapsulation: A list_t provides "modest" encapsulation.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Lecture10-ADT-intro - Last time: * exceptions Next few...

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

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