Class Relationships - PowerPoint PPT Presentation

About This Presentation
Title:

Class Relationships

Description:

Class Relationships Lecture Oo09 Association Relationships References Ambler, S., The Object Primer, Cambridge Univ. Press, 2001, Section 5.7, 5.8 Teaching Points ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 20
Provided by: electrical
Category:

less

Transcript and Presenter's Notes

Title: Class Relationships


1
Class Relationships
  • Lecture Oo09
  • Association Relationships

2
References
  • Ambler, S., The Object Primer, Cambridge Univ.
    Press, 2001, Section 5.7, 5.8

3
Teaching Points
  • Association Relationships
  • Aggregation
  • Composition

4
Review
  • How can we get the effect of run-time binding in
    non-OO languages?
  • e.g. Who_AM_I()

5
Class Diagrams
  • Provide a static view of the design
  • The types of objects in the design and the static
    relationship between them
  • Three perspectives
  • Conceptual
  • Specification
  • Implementation

6
Association Relationships
  • Associations usually represent objects of one
    class making use of objects of another class

7
Association Relationships
  • Conceptual
  • conceptual relationship
  • Specification
  • responsibilities
  • methods implied
  • Implementation
  • visibility (pointers)
  • navigability

8
Roles
9
Multiplicity (Cardinality)
  • 1 only one
  • 1.. one or more
  • 0..1 zero or one
  • 0.. zero or more (also )

10
Aggregation
  • A kind of association used to model whole-part
    relationships
  • The whole is a container or composite
  • The things being aggregated can be called parts
    or components

11
Aggregation
12
Benefits of showing Aggregation
  • Clarifies whether the part can exist independent
    of the whole
  • impacts create/delete dependencies
  • Assists in identifying the creator
  • Operations such as copy, move, delete, etc.
    should often be propagated to the parts
  • Parts hidden within the whole can provide better
    encapsulation

13
Composition
  • A kind of aggregation
  • Stronger relationship than plain aggregation
  • The part object may belong to only one whole
  • The parts live and die with the whole
  • In implementation the component is structurally
    part of (a field of) the whole

14
Composition
15
Aggregation vs. Association
  • It is not always obvious when to use association
    and when to use aggregation
  • There are differing views in the OO world
  • Aggregation often starts out as association, but
    as the semantics of the problem are refined an
    association can become aggregation
  • More important at the implementation perspective

16
When to use Aggregation
  • The lifetime of the part is bound within the
    lifetime of the aggregate - there is a create
    delete dependency of the part on the whole.
  • There is an obvious whole-part physical or
    logical assembly

17
When to use Aggregation
  • Some properties of the composite propagate to the
    parts, such as its location
  • Operations applied to the composite propagate to
    the parts, such as destruction, movement,
    recording, etc.
  • If in doubt, leave it out.

18
Composite Pattern (Review)
  • May be used to describe
  • File system
  • Graphics objects
  • Aircraft Components
  • etc.

19
Teaching Points
  • Association Relationships
  • Aggregation
  • Composition
Write a Comment
User Comments (0)
About PowerShow.com