Professional Documents
Culture Documents
Data Structures and Algorithms
Data Structures and Algorithms
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:
input
Black box
Data Abstraction
Data Abstraction
public
method
Hidden data
representation
Data Abstraction
public
method
Data Abstraction
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
integer
++
||
~
boolean
Data Abstraction
&&
Primitive ADT
Types of Operation
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