pick of the day 10-jan-2003 lecture 2 crash course on oo analysis models
TRANSCRIPT
pick of the day
10-Jan-2003
Lecture 2
Crash course on OO Analysis Models
January 10 2003 Lecture 2 2
Outline
Previous Business Survey Results
Constructor Challenge Results
Reading Questions
Crash course in OO modeling
Continuing Mini-Example
January 10 2003 Lecture 2 3
Survey Results
Topics of interest Primary
• OOD
Secondary• UML, OOP, Design Patterns, Software Architecture
Tertiary• Security, Swing, Transactions,
Quaternary• Persistence, Domain Analysis
January 10 2003 Lecture 2 4
Reading Questions
What is the “inherent identity” that Lau considers objects to have? [p. 1]
Book b = new Book ();Book b2 = b;Book b3 = new Book();
// identity checked by comparing object references
b == b2 // true
b2 == b3 // false
January 10 2003 Lecture 2 5
Equality tangent
What is difference between == and equals
Book b = new Book ();Book b2 = new Book();
// only Book class knows the answer
if (b.equals (b2)) {
}
equals must be reflexive, symmetric, transitive
January 10 2003 Lecture 2 6
Reading Questions
Object state is set by the object’s operations. Is this the only way to set an object’s state?
No: 1) constructor can set initial state
2) class attributes can be pre-set
upon construction
3) Thread of computation within object can alter values
January 10 2003 Lecture 2 7
Reading Questions
What is the difference between uni-directional and bi-directional associations?
Category Book1 *
The underlying link between the objects is one-way for unidirectional associations but two-way for bi-directional associations
Category
Books:Book[*]
Book
January 10 2003 Lecture 2 8
Reading Questions
What is the practical impact of maintaining a bidirectional association?
1) referential integrity
2) simultaneous creation
A B
A B
A
January 10 2003 Lecture 2 9
Binary Associations
Familiar to C programmers
Links are realizations of associations Unidirectional: object reference (pointer)
Bi-direction: more than doubly-linked list
What is accessscope of object?
What are core operations?
January 10 2003 Lecture 2 10
Binary Association Alternatives
Does Book know of its Category “parent”?
Does Category maintain “ownership” over the aggregate set?
Can a change to a Book impact/invalidate set?
Who is responsible for add/remove?
Does the relationship scale to 10,000 books? 10,000,000 books?
Category Book1 *
January 10 2003 Lecture 2 11
N-ary associations
How common are they?a complex set of binary associations can be greatly simplified through an n-ary association
Committee
Year
Person
post
<c,p>
<y,p>
<y,c>
0..2
1..4
3..5
Committee
Year
Person
Post
*
*
*
*
**
January 10 2003 Lecture 2 12
Aggregation and CompositionNormal AssociationAggregation
special binary association between aggregate (the set) and its elements“operations on whole are propagated to subparts”
Composition stronger than aggregation, implies that a sub-part is integral part of greater whole “whole cannot exist without subpart” but “subpart can exist without whole”
Differences are subtle and may be refined later.
January 10 2003 Lecture 2 13
Aggregate Composition Quiz
Category –––– Book
Frame –––– Button
Canvas –––– Font
Course –––– Student
Polygon –––– Point
Student –––– Identifier
January 10 2003 Lecture 2 14
Aggregation/Composition Summary
Characteristic Normal Association
Aggregation Composition
UML
Ownership None Weak Strong
Multiplicity Any Any One : Any
Transitivity No Yes Yes
Propagation of properties
Undefined Whole to Part Whole to Part
January 10 2003 Lecture 2 15
Servant Classes & Delegation
To reduce complexity and increase cohesion
create new class as servant to existing class
servant object has only one “master”
operations are delegated to servant object
Lau claims this leads to higher abstraction and better reuse. Why?
January 10 2003 Lecture 2 16
Inheritance vs. Servant
Point
real x, y
Circle
Circle uses (x,y) as center
But this can’t be right!
Point
real x, y
CirclePoint center
abstract
reuse
January 10 2003 Lecture 2 17
Monday Assignments
Read: TAOO: Chapter 2.1 – 2.4
Modeling exercisetry to model Person, Committee, Year as only binary relationships
try to model Post as a separate class to manage Person/Committee/Year relationships
Exercise 2-1, 2-2
January 10 2003 Lecture 2 18
References
none