Lect 06

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Thought for the Day

What we think or what we know or


what we believe is, in the end, of little
consequence. The only consequence is
what we do.
– John Ruskin
Abstraction
• Complexity is hard for humans to deal with

• In many areas of life we use abstraction to


deal with complexity
Abstraction in Modern
Programming Languages
• Procedural Abstraction
– Methods allow us to use and to create abstract
procedures or processes

objStream.writeObject(obj);

calculateTax(employee[k]);
Abstract Data Types
Data Abstraction
• View data in an abstract way

• Formal definition:
An Abstract Data Type is a pair <V, O> where:
V is a set of values
O is a set of operations defined on V

• Abbreviate: ADT
Basic Data Types
• Types such as int, double, etc. are “built
in” ADTs

• For int in Java:


V = { -2 147 483 648 ... 2 147 483 647 }
O = { +, -, *, /, %, ~, |, &, ^, <<, >>,
>>>, <, <=, ==, >=, >, !=, = }
New Abstract Data Types
• Many programming languages allow us to
create our own new ADTs
• Java: class
• Example:
– Towers of Hanoi “Tower” class
V = { stacks of n ≥ 0 disks of diff. sizes }
O = { add, remove, getID }
Client and Implementor Views
• ADTs allow us to hide details of the
implementation from “clients”
– Vital for abstraction

• In Java: private

• Try to keep separate:


– implementor view
– client view
Client Views
• In the notes, distinguished by grey
background

• Also use simplified UML class diagrams:

Tower
disks, numDisks, ID
Tower
add, remove, getID
Interfaces and Data Abstraction
• Sometimes a client will use an object
defined by an interface

• It does not need to know anything else


about the type of the actual object
– Hidden implementation detail
void delegate (ManagerialResponsibilities m)
{ ... m.manage(); ...
} // delegate
Closing Comment
• Geoff Rehmet (Technical Business
Manager, Internet Solutions):

…the single most powerful construct I learned


[at Rhodes] is the concept of abstraction.
… [it] gives me an infinite lead over my peers

You might also like