You are on page 1of 10

Data Structures and

Algorithms
Abstract Data Type

Important of Abstraction
Structure large system into layered
components
Allow programs code to be more
generic/reusable
Allow focus of what (specification) to be
separated from how (implementation)
Use modularity for local changes

Data Abstraction

Procedural Abstraction

Achieve by:

Threat function as black box


Give specification of its purpose
output

input
Black box

Dont need to know detail algorithm

Data Abstraction

Data Abstraction

Focus on what the data structure can do,


rather than how it can be represented

public
method

Hidden data
representation

Data Abstraction

public
method

Data Abstraction

Why Data Abstraction


Hide unnecessary details
Help manage software complexity
Easier software maintenance
Functionalities are less likely to change
Localized rather than global change

Data Abstraction

Key Technique

Data encapsulation
Keeping data and operation together in one
place

Information Hiding
Restricting visibilities of implementation
details to where needed

Data Abstraction

Primitive Data Type

integer

++

||

~
boolean

Data Abstraction

&&

Primitive ADT

Types of Operation

Constructor: object creator


int x[ ] = {1,2,3,4}

Mutator: object updater


x[3] = 10

Accessor: object querier


int y = x[3]

Destroyer:object terminator
garbage colector
Data Abstraction

ADT Example
real
add(c)

Complex(r,i)
complex

times(c)

minus(c)
Imajiner

Complex number

Data Abstraction

ADT Example
Class Complex {
constructor
private
Complex( real r, real i); // this.r = r; this.i = I
add(Complex c);
// this.add(c)
minus(Complex c); // this.minus(c) mutator
times(Complex c); // this.times(c)
getReal();
// return this.r
accessor
getImajiner();
// return this.i

}
Data Abstraction

You might also like