13Jan2003 - PowerPoint PPT Presentation

About This Presentation
Title:

13Jan2003

Description:

Office hour for Kate Dimitrova canceled today ... What is the essential difference between a collection manager and container? ... Composition Litmus Test: ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 21
Provided by: georgeh1
Learn more at: http://web.cs.wpi.edu
Category:
Tags: 13jan2003 | litmus

less

Transcript and Presenter's Notes

Title: 13Jan2003


1
Common Patterns in Static Design
  • 13-Jan-2003
  • Lecture 3

2
Outline
  • 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.

3
Reading 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.
4
Reading 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.
5
Reading 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.
6
Reading 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.

7
Collection 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

8
Motivation for loops? which one?
1
1
3
Container
Container
1
Container
2
4
1
9
Self-containing data structures
  • Graph data structures in C

typedef struct node char node node
parent int numChildren node
children NODE, NODE_PTR
10
Self-containing classes
children
The association has itsimplementing link
withforward back references
1
Node
Node

parent
Class Node ltltstructuregtgt Node parent
Node children
11
Self-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?

12
Composite Example (freebie!)
Container

Container

1
1
Try to copy these
Try to resize these
13
Self-containing classes
  • Two approaches

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
14
Differences 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

15
Self-containing classes
Node
Node

Node



1
ComplexNode
ComplexNode
ComplexNode
Relationship Loop Common with rich domain
modeling
16
How 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

17
Consequences 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
18
Relationship without containment
Version
previous
1
Revision
0..1
next
19
Tuesday 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!

20
References
  • none
Write a Comment
User Comments (0)
About PowerShow.com