Beruflich Dokumente
Kultur Dokumente
Inheritance
Polymorphism and dynamic binding
Java an example of an object-oriented programming language
Program example
History of Java
Comparison to C/C+
OOP: Introduction
Mammal
Tusks
Four legs
Herbivorous (plant eater)
OOP: Introduction
behavior (methods)
OOP: Introduction
OOP: Introduction
outside world.
Data can only be accessed via methods.
Data
OOP: Introduction
send
message
Data
Function
Method
Function
Method
Function
Method
Procedural
Class
world.
The hidden data and methods can be changed without
affecting the outside world.
Outside world
An object
Client interface
Object
A representation of the
properties of a single
instance.
A phenomenon.
An object is part of data
and a program execution.
Example 1: Person
Example 2: Album
OOP: Introduction
source http://www.filflora.com
To get an object
To send a message
OOP: Introduction
Type
Interface
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
OOP: Introduction
Dynamic Instantiating
In the method part of a
program.
A dynamic instance is
created explicitly with a
special command.
10
O1 sends O2 a message
message
O3
O2
message
11
an object
a class
Characteristics of a concept
A name
Intension, the set of properties of the phenomenon
Extension, the set of phenomena covered by the concept.
OOP: Introduction
12
numbers:
words:
dinosaur:
mammal:
OOP: Introduction
13
belongs to a concept.
An exemplification is a phenomenon that covers the concept
Concept
classification
exemplification
Phenomenon
OOP: Introduction
14
Car
Aggregation
Engine
Gearbox
Doors[4]
start()
drive()
new class
15
Concept
decomposition
aggregation
Concept
OOP: Introduction
16
OOP: Introduction
17
Concept C
specialization
generalization
Concept B
Concept D
Vehicle
Car
Hatchback
OOP: Introduction
Station car
Truck
Sedan
Pickup
18
Line
draw()
resize()
Rectangle
draw()
resize()
Square
draw()
resize()
OOP: Introduction
19
OOP: Introduction
Line
Rectangle
20
// dynamic binding
objects.
Dynamic binding: How polymorphism is implemented.
OOP: Introduction
21
remove inheritance
remove general and abstract class Shape
OOP: Introduction
Rectangle
draw()
resize()
Square
draw()
resize()
Circle
draw()
resize()
Line
draw()
resize()
22
Similar code
is repeated
23
variable
method header
method body
OOP: Introduction
24
25
MyProg.cpp
javac MyProg.java
gcc MyProg.cpp
-o myprog.exe
Java Class File
MyProg.class
Portable Byte Code
Java Virtual Machine
Executable myprog.exe
Operating System
Operating System
Java/C# world
C++ world
OOP: Introduction
26
History of Java
1990 Oak (interactive television, big failure)
1994 Java (for the Internet)
Designed for
OOP: Introduction
27
Garbage collection
28
Summary
Classes are recipes for creating objects
All objects are instances of classes
Encapsulation
has-a relationship
Polymorpishm/dynamic binding
OOP: Introduction
29
30
OOP: Introduction
31
Everything in an object.
A program is a set of objects telling each other what to do by
sending messages.
Each object has its own memory (made up by other objects).
Every object has a type.
All objects of a specific type can receive the same messages.
OOP: Introduction
32