LECTURE 2: The Object Model: Ivan Marsic Rutgers University
LECTURE 2: The Object Model: Ivan Marsic Rutgers University
Ivan Marsic
Rutgers University
Topics
• Objects and Method Calls
• Interfaces
• UML Notation
• Object Relationships
Result:
YES!
Stu Elmer
Object:
method-1: method-2: method-3:
ATM machine
Accept card Read code Take selection
1234
5678
1
4 2
7 5 3
8 6
0 9
12345
1
4 2
7 5 3
8 6
0 9
Object Interface
Interface defines method “signatures”
Method signature: name, parameters, parameter types, return type
Interface
attributes
method-1 Object hides its
state (attributes).
method-2 The attributes
are accessible
only through the
method-3 interface.
Clients, Servers, Messages
Client
Client Object
Object Server
Server
Object
Object
Message
Software Module
Data
(state)
Software Class
«interface»
Inheritance
BaseInterface
relationship:
ClassName BaseInterface
+ operation()
is implemented
# attribute_1 : int by two classes
Three compartments: # attribute_2 : boolean
# attribute_3 : String
1. Classifier name
+ operation_1() : void
+ operation_2() : String Class1Implement Class2Implement
2. Attributes
+ operation_3(arg1 : int)
+ operation() + operation()
3. Operations
Object Relationships (1)
• Composition: using instance variables that are references to other objects
Composition
Derived Class B
B acts as “front-end” for A and uses services of A
+ operation()
(i.e., B may implement the same interface as A)
Inheritance
Object Relationships (2)
• Both inheritance and composition extend the
base functionality provided by another object
• INHERITANCE: Change in the “base” class
propagates to the derived class and its client
classes
– BUT, any code change has a risk of unintentional
introducing of bugs.
• COMPOSITION: More adaptive to change,
because change in the “base” class is easily
“contained” and hidden from the clients of the
front-end class
Object-Oriented versus
Process-Oriented Approaches
System
1
2
3
4
5
X
Y
Key
Key unlock() Lock
Lock turnOn() Light
Light
(b) Checker
Checker Ctrl
Ctrl Ctrl
Ctrl
Valid No
key
?
Unlock the
Key
Key Lock
Lock Light
Light
lock (c) Checker
Checker Ctrl
Ctrl Ctrl
Ctrl
Turn the
light on
• Object-oriented is organization-centric
– But, hard to design well organizations…
How To Design Well OO
Systems?
• That’s the key topic of this course!
CO-3 Code-3
Requirements
Engineering Use Cases OOA/OOD Implementation
(Section 2.2) (Section 2.3) (Sections 2.4 & 2.5) (Section (2.7)
90 45
Relativity Waterfall
Security
Conflicting needs
of computer security…