adt data abstraction. abstraction representation of concepts by their relevant features only ...

15
ADT data abstraction

Upload: dominic-berry

Post on 18-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

ADTdata abstraction

Page 2: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Abstraction

representation of concepts by their relevant features only

programming has two major categories of abstraction process abstraction

(procedures) data abstraction

(abstract data types -> objects)

Page 3: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Process abstraction

external view: for caller of procedure – only the preconditions and effect of the process are relevant

internal view: for implementer of procedure – details of how to achieve effect starting from preconditions are important

Page 4: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Process abstraction

advantages reusable procedures revision of procedures independent of

usage

-> model for large programming projects – control of complexity, separation of tasks

Page 5: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Steps toward ADT process abstraction inadequate – not

enough organizing structure modules

group related procedures (and data) together

compilation units make groups as independent as possible

(avoid recompilation – recall distinction of separate and independent compilation)

Page 6: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Steps toward ADT

encapsulation independently compilable units with

support for internal structure visible interfaces for use by other units

using them (types, procedure protocols, for error checking)

Page 7: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Abstract Data type (think Objects)

encapsulation for one data type (record?) and its operations

e.g. complex number type with arithmetic ops user program can create instances and

apply operations user program cannot manipulate (or

even see) internal structure

Page 8: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Complex number ADT

ADT to represent and operate on complex numbers behaviour - external

representation of a complex number operations on complex number objects

implementation - internal internal variables methods code

Page 9: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Complex number ADT

ADT Cpx behaviour

representation of a complex number string: “3 - 4i” or “(5,pi/4)”

operations on complex number objects new(real, imaginary); new(magnitude, angle) getReal, getImaginary,

getMagnitude, getOrientation add, subtract, multiply, divide, power

e.g., function add(Cpx x,Cpx y)returns Cpx

Page 10: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Complex number ADT

ADT Cpx implementation - internal

internal variables double real double im

methods code function add(Cpx x,Cpx y)returns Cpx

z = new Cpx(x.real+y.real, x.im+y.im)return z

Page 11: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

User defined ADTs language capability for programmer

to create, compile and use new ADTs the same way as built-in ADTs compile to make types, protocols visible

with implementation invisible any built-in/”inherited” features for all

ADTs? e.g. copy, compare, assign any restrictions on ADT types?

simplicity/flexibility tradeoff e.g. parameterized ADTs, references only

Page 12: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Ada C++ Java

Package Class Package and class

Specification package (interface info for independent compilation)

And

Body package

(implementation of procedures)

p. 480

Class with privacy controls for information hiding

NO higher level structure like package

Friend functions with access to private structure

Class with privacy controls

And

Package for organizing and mutual access

EVERYTHING is ADTs

(no independent methods/functions)

Page 13: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Ada C++ Java

Package Class Package and class

Template classes can be used with different types

Instances of classes are allocated on run-time stack (may contain heap dynamic instance variables)

Generic classes; Wrapper classes

Object hierarchy provides same power (except for primitive types)

Only references are on run-time stack – all instance objects on heap

Contains (many) types and procedures

NOT methods

Parameterized

e.g. collection package usable for different element types

Page 14: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Ada format

Specification package Types Procedure protocols Some are ‘private’ – invisible to user

programs Body package

procedure code

Page 15: ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process

Java abstraction concepts - ADTs and more --> objects

class interface abstract class generic class inheritance hierarchy wrapper class