CS112_19_Slides-ADTs1 - Abstract Data Types ADT Yinglin...

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

View Full Document Right Arrow Icon
S112 Fundamentals of Abstract Data Types— ADT Yinglin Wang CS Dept., SJTU
Background image of page 1

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

View Full DocumentRight Arrow Icon
S112 Fundamentals of Today we start on our next major theme— Abstract Data Types (ADTs ) The idea is to implement the behavio r of a new data type in a way that hide s the details from the client behind the "wall of abstraction". The interface specifies how the client calls functions in the implementation. Eac h part is unaware of what is happening on the other side of the wall. Here th e abstract data type is something called a widgetADT. With ADTs, we will have a standard way of creating new objects. The ADT will always be a pointer type, and there will always be a function like NewWidget that returns a pointe r of that type.
Background image of page 2
S112 Fundamentals of The NewWidget function allocates storage for the object on the implementation side, but the client does not know what the structure is, because it is on the other side of the wall. From the client's standpoint, the ADT is defined by its behavior, not its structure, and the behavior is defined by the set of functions exported by the interface.
Background image of page 3

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

View Full DocumentRight Arrow Icon
S112 Fundamentals of Here is a quick review on declaring pointer types. Something is missing on the right side! user doesn’t point to anything yet.
Background image of page 4
S112 Fundamentals of If we now turn our attention to the implementation code, we can remove the question mark, because the implementation has full access to the structure of the ADT.
Background image of page 5

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

View Full DocumentRight Arrow Icon
S112 Fundamentals of Often the New ... function will do some initialization in addition to allocating the storage. For example, maybe the field n should always start at 0.
Background image of page 6
S112 Fundamentals of The client can call the exported functions, which have an effect over on the implementation side. Though the data is specified by the client through the parameters to the function call, the client can't change the data structure directly. Only the code on the implementation side can change these fields on the client's behalf.
Background image of page 7

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

View Full DocumentRight Arrow Icon
S112 Fundamentals of The FreeWidget function frees the storage, and all our ADTs will have such a function. What does
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.

This note was uploaded on 04/06/2010 for the course CS 112 taught by Professor Yinlinwang during the Spring '08 term at Shanghai Jiao Tong University.

Page1 / 30

CS112_19_Slides-ADTs1 - Abstract Data Types ADT Yinglin...

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