Object Interaction
Object Interaction
Part I:
Foundations of object
orientation
Object interaction
MSc. Fernando A. Rojas Morales
3.0
abstraction
modularization
object diagrams
object creation
method calls
debuggers
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
Application Domain
Solution Domain
System Model
TrafficControl
Aircraft
UML Package
TrafficController
FlightPlan
Airport
SummaryDisplay MapDisplay
FlightPlanDatabase
TrafficControl
Object-Oriented Software Engineering Using UML, Patterns, and Java by Bernd Bruegge
Abstraction and
modularization
Abstraction is the ability focus your
attention on essentials and ignore
irrelevant details of a system.
Modularization is the process of
dividing a whole into well-defined
parts, which can be built and
examined separately, and which
interact in well-defined ways.
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
A digital clock
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
Or two two-digit
displays?
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
Implementation NumberDisplay
public class NumberDisplay
{
private int limit;
private int value;
Constructor and
methods omitted.
}
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
Implementation ClockDisplay
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
Constructor and
methods omitted.
}
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
10
Object diagram
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
11
Object Diagram
The object diagram shows the
objects and their relations in a given
moment of a running application.
It depicts the dynamic view.
The variables of type object store
references to objects (not the
objects themselves).
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
12
Class diagram
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
13
Class Diagram
The class diagram shows the classes
of an application and the relation
among them.
The class diagram gives information
about the code.
The class diagram shows the static
view.
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
14
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
15
object type
int i;
32
primitive type
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
16
Primitive types
Primitive types are not Objects.
Primitive types are all predefined in
the Java language: int, boolean,
char, double, long. [Appendix B].
Primitive types dont have methods.
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
17
18
ObjectType b;
b = a;
int a;
int b;
32
32
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
19
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
20
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
21
22
23
Quiz
What is the result of the expression
8%3
Can n be negative?
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
24
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
25
Logic Operators
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
26
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
27
28
29
actual parameter
in class NumberDisplay:
public NumberDisplay( int rollOverLimit );
formal parameter
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
30
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
31
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
32
Overloading
It is common for class definitions to
contain alternative versions of
constructors or methods that provide
various ways of achieving a particular
task via their distinctive sets of
parameters.
This is known as overloading a
constructor or method.
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
33
Multiple constructors
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
34
35
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
36
37
Method calls
NB: A method call on another object
of the same type would be an
external call.
Internal means this object.
External means any other object,
regardless of its type.
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
38
null
null is a special value in Java
Object fields are initialized to null
by default.
You can test for and assign null:
private NumberDisplay hours;
if( hours != null ) { ... }
hours = null;
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
39
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
40
41
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
42
The debugger
Useful for gaining insights into
program behavior
whether or not there is a program
error.
Set breakpoints.
Examine variables.
Step through code.
43
44
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
45
name overloading:
System.out.println( from )
Which variable will be usedthe
parameter or the field?
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
46
Using a debugger
Setting breakpoints
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
47
Single stepping
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
48
Concepts
abstraction
modularization
classes define
types
class diagram
object diagram
object references
primitive types
object types
object creation
overloading
internal/external
method call
debugger
Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes, Michael Klling
49