Abstract Data Type
(ADT)
• An ADT is a collection of objects (or values) and a
corresponding set of methods.
• An ADT encapsulates the data representation and makes data
access possible at a higher level of abstraction.
• Example 1: A set of vehicles with operations for starting,
stopping, driving, get km/liter, etc..
• Example 2: A time interval, start time, end time, duration,
overlapping intervals, etc.
Encapsulation and Information Hiding
Data can be encapsulated such that it is invisible to the "outside
world".
• Data can only be accessed via methods.
Data
Function
Function
Function
Data
Method
Method
Method
Procedural ADT
Encapsulation and Information Hiding, cont.
• What the "outside world" cannot see it cannot depend on!
• The object is a "fire-wall" between the object and the "outside
world".
• The hidden data and methods can be changed without affecting
the "outside world".
Hidden data and methods
Client interface
An object Visible data and methods
Class vs. Object
Class• A description of thecommon properties of aset of objects.• A concept.• A class is a part of aprogram.• Example 1: Person• Example 2: Album
Object
• A representation of the
properties of a single
instance.
• A phenomenon.
• An object is part of data
and a program execution.
• Example 1: Bill Clinton,
Bono, Viggo Jensen.
• Example 2: A Hard Day's
Night, Joshua Tree, Rickie
Type and Interface
• An object has type and an interface.
Account
balance()
withdraw()
deposit()
Type
Interface
• To get an object Account a = new Account()
• To send a message a.withdraw()
Instantiating Classes
• An instantiation is a mechanism where objects are created from
a class.
• Always involves storage allocation for the object.
• A mechanism where objects are given an initial state.
Static Instantiating
• In the declaration part of a
program.
• A static instance is implicitly
created
Dynamic Instantiating
• In the method part of a
program.
• A dynamic instance is
created explicitly with a
special command.
OOP: Introduction 10
Interaction between Objects
• Interaction between objects happens by messages being send.
• A message activates a method on the calling object.
• An object O1 interacts with another object O2 by calling a
method on O2 (must be part of the client interface).
“O1 sends O2 a message”
• O1 and O2 must be related to communicate.
• The call of a method corresponds to a procedure call in a nonobject-
oriented language such as C or Pascal.
No comments:
Post a Comment