Professional Documents
Culture Documents
2 1 OOP Introduction
2 1 OOP Introduction
2 1 OOP Introduction
Continuing OOP
Introduction
Lecture 2
CMSC 432
Shon Vick
1
UMBC
Objectives
Everything is an object
Computation is performed by objects
communication with each other, requesting that
others perform action
Objects communicate by sending and receiving
messages. A message is a request for action
bundled with whatever argument is necessary to
complete the task
Each object has its own memory which consists
of other objects
4
UMBC
Another view of OOP
5
UMBC
Inheritance
6
UMBC
Inheritance (cont’d)
subclass superclass
or extends or
derived class base class
7
UMBC
Inheritance (cont’d)
8
UMBC
Inheritance (cont’d)
9
UMBC
Inheritance (cont’d)
10
UMBC
Inheritance (cont’d)
Inheritance leads to a hierarchy of classes
and/or interfaces in an application:
Game
Solitaire GameFor2
BoardGame
Chess Backgammon
11
UMBC
Inheritance (cont’d)
JComponent
JPasswordField JTextPane
12
UMBC
Inheritance (cont’d)
14
UMBC
Summary (cont)
15
UMBC
Coping with Complexity
16
UMBC Method Binding and
Polymorphism
17
UMBC Sending Messages
vs. Procedure Call
A message has a designated receiver (some
object)
The interpretation of the message, I.e. the
method used in response to the message is
determined by the receiver and can vary
amongst different receivers.
Often the actual receiver of a message is
not known until run-time. There is late or
dynamic binding between the message and
the code fragment (method) used to
respond to the message
18
UMBC
Functions are not Methods
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
Methods are not Functions Methods are not Functions Methods are not Functions Methods are not Functions
19
UMBC Responsibility &
Abstraction
Discussing a problem in terms of responsibilities
increases the level of abstraction and permits greater
independence between agents
The entire collection of responsibilities associated
with an object is often described by the term protocol
A receiver takes responsibility for responding to a
message; the sender of the message need not know the
details of the method used. This is a standard
powerful form of abstraction sometimes called
information hiding
20
UMBC
Categories surrounding Fred
Material Object
Animal
Mammal
Human
Shopkeeper
Florist Fred
21
UMBC
Classes and Instances
Although Chris does not know Fred very he has a
rough idea of the transactions that occur inside
Fred’s shop. Chris is able to make certain
assumptions based on previous experiences with
florists. He expects that Fred, being an instance of
the category florist, will match the pattern.
All objects are instances of a class. The method
invoked by an object to respond to a message is
determined by the class of the receiver. All
objects of the same class use the same method in
response to the same message.
22
UMBC A Material Objects Class
Hierarchy
Material Object
Animal Plant
Mammal Flower
Florist Potter
Fred Ken
23
UMBC
Encapsulation and Instantiation
25
UMBC State - Instance Variables
26
UMBC Interface and
Implementation
End of Lecture
28
UMBC
Abstraction
29
UMBC
Abstraction layers in OOP
30
UMBC
Abstraction layers in OOP
31
UMBC
General Forms of Abstraction
Specialisation patterns
“is a” service view
OO programs
recursive algorithms
abstraction division into parts repetition recursive data structures
“has a”
composition
catalogs
cross-references
32
UMBC Abstraction mechanisms in
programming languages
Procedures and Functions (function centered
view)
+ information hiding for the detail of the behavior
- no information hiding for the detail of the data
- no encapsulation
Modules and Packages (data centered view)
+ information hiding
+ encapsulation
- instantiation not always supported
Abstract Data Types
+ separates interface and implementation
33
UMBC Abstraction mechanisms in OO
programming languages
34
UMBC
Object Oriented Design
35
UMBC
References
36