19_Slides-ADTs1 - AbstractDataTypesADT YinglinWang...

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

View Full Document Right Arrow Icon
CS112 Fundamentals of  Programming Abstractions 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
CS112 Fundamentals of  Programming Abstractions Today we start on our next major theme—Abstract Data Types (ADTs). The idea is to implement the behavior of a new data type in a way that hides the details from the client behind the "wall of abstraction". The interface specifies how the client calls functions in the implementation. Each part is unaware of what is happening on the other side of the wall. Here the 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 pointer of that type.
Background image of page 2
CS112 Fundamentals of  Programming Abstractions 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
CS112 Fundamentals of  Programming Abstractions 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
CS112 Fundamentals of  Programming Abstractions 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
CS112 Fundamentals of  Programming Abstractions 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
Programming Abstractions 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
Image of page 8
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

19_Slides-ADTs1 - AbstractDataTypesADT YinglinWang...

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

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