Title: 13Jan2003
1Common Patterns in Static Design
2Outline
- Previous Business
- Office hour for Kate Dimitrova canceled today
- Java Help sessions TODAY TOMORROW
- Committee, Year, Person (examples)
- Reading Questions
- Lecture Contents
- Collection Managers vs. Containers
- Relationship Loops
- Web page synchronization off by a day. Check
revised syllabus tonight at 11PM.
3Reading Questions
- What is the essential difference between a
collection manager and container?
Collection Manager is responsible for creating an
object to be added to the collection. Container
accepts objects to be added into the collection.
4Reading Questions
- Why does Collection Manager have binary
association while Container is aggregate?
While there must be a relationship
(ManagerEntity) the distinction is abstract.
The Manager is responsible only for creating the
Entity objects and thereafter provides an index
capability. The (ContainerInnerObject) on the
other hand is stronger and implies an on-going
relationship between the Container and its inner
objects.
5Reading Questions
- Why isnt the ContainerObject a composition
relationship?
Composition Litmus Test whole cannot exist
without subpart but subpart can exist without
whole This is not true with the Container.
6Reading Questions
- How does Container provide the remove
(nameString) capability?
- The Object must have some polymorphic method to
be used. Java has toString() but this is not
going to be strong enough, I believe. - Either a common-superclass for all objects being
added into the container. - Or provide a common interface that all objects
being added must implement.
7Collection Manager Containers
- Collection managers
- take responsibility for creating objects
- the only way to create an object is through the
manager (like a factory) - Containers
- useful for when there is a need to treat an
aggregate set of objects as an object in its own
right
8Motivation for loops? which one?
1
1
3
Container
Container
1
Container
2
4
1
9Self-containing data structures
- Graph data structures in C
typedef struct node char node node
parent int numChildren node
children NODE, NODE_PTR
10Self-containing classes
children
The association has itsimplementing link
withforward back references
1
Node
Node
parent
Class Node ltltstructuregtgt Node parent
Node children
11Self-containing classes
- What if there are complex nodes?
- Can we treat complex nodes the same way as we
treated regular nodes? - Is there only one type of complex node, or do
they come in a wide variety? - Are operations similar between regular nodes and
complex nodes? - What if aggregation is present?
- Can regular nodes be grouped together?
- Can these aggregations be considered to be nodes?
12Composite Example (freebie!)
Container
Container
1
1
Try to copy these
Try to resize these
13Self-containing classes
Class Node ltltstructuregtgt Node parent
Node children ComplexNode bigChildren
Class Node ltltstructuregtgt Node parent
Node children
children
1
children
Node
Node
1
Node
Node
parent
parent
1
ComplexNode
ComplexNode
bigChildren
14Differences of these approaches
- ComplexNode as new aggregate
- must re-implement methods that are nearly
identical - maintains clear separation
- search more complicated
- ComplexNode as subclass
- parent nodes can now be Complex
- reuse existing structure because ComplexNodes
are Nodes - There must be a drawback to subclass. Seems too
good
15Self-containing classes
Node
Node
Node
1
ComplexNode
ComplexNode
ComplexNode
Relationship Loop Common with rich domain
modeling
16How to identify?
- Seek out multiple aggregate relationships from
the same base - Determine appropriate type of relationship
- Backward or Forward containment
A
A
children
1
Node
Node
parent
1
B
B
ComplexNode
17Consequences of Self-containing
A
- Backward
- specialized node contains links
- enables variable aggregationby subclass(es)
- Forward
- aggregate link is inherited
- watch for unexpected behavior!
B
A
B
18Relationship without containment
Version
previous
1
Revision
0..1
next
19Tuesday Assignments
- Modeling exercise
- try to model Post as a separate class to manage
Person/Committee/Year relationships - try to think of ways in which this simplifies
the problem - Exercises
- none
- Review 2.1 2.4
- Really Review 2.1 2.4!
20References