Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pick of the day 13-Jan-2003 Lecture 3 Common Patterns in Static Design.

Similar presentations


Presentation on theme: "Pick of the day 13-Jan-2003 Lecture 3 Common Patterns in Static Design."— Presentation transcript:

1 pick of the day 13-Jan-2003 Lecture 3 Common Patterns in Static Design

2 January 13 2003Lecture 32 Outline Previous Business Office hour for Kate Dimitrova canceled today Java Help sessions TODAY & TOMORROW Committee, Year, Person (examples)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 January 13 2003Lecture 33 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 January 13 2003Lecture 34 Reading Questions Why does Collection Manager have binary association while Container is aggregate? While there must be a relationship (Manager::Entity) the distinction is abstract. The Manager is responsible only for creating the Entity objects and thereafter provides an index capability. The (Container::InnerObject) on the other hand is stronger and implies an on-going relationship between the Container and its inner objects.

5 January 13 2003Lecture 35 Reading Questions Why isn’t the Container::Object 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 January 13 2003Lecture 36 Reading Questions How does Container provide the remove (name:String) 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. 1)Either a common-superclass for all objects being added into the container. 2)Or provide a common interface that all objects being added must implement.

7 January 13 2003Lecture 37 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 January 13 2003Lecture 38 Motivation for loops ? which one ? Container 1 * 1 1 1 1 24 3

9 January 13 2003Lecture 39 Self-containing data structures Graph data structures in C typedef struct node { char *node; node *parent; int numChildren; node *children[]; } NODE, *NODE_PTR;

10 January 13 2003Lecture 310 How important is this link? Self-containing classes Node 1 * children parent The association has its implementing link with forward & back references Class Node { > Node parent; Node children[*]; }

11 January 13 2003Lecture 311 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 January 13 2003Lecture 312 Composite Example (freebie!) Container 1 * 1 * 1 * 1 * Try to copy theseTry to resize these

13 January 13 2003Lecture 313 Self-containing classes Two approaches Class Node { > Node parent; Node children[*]; ComplexNode bigChildren [*]; } Node 1 * children parent ComplexNode bigChildren 1 * Class Node { > Node parent; Node children[*]; } Node 1 * children parent ComplexNode

14 January 13 2003Lecture 314 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 January 13 2003Lecture 315 Self-containing classes Node 1 * ComplexNode + Node ComplexNode = * Node ComplexNode Relationship Loop – Common with rich domain modeling

16 January 13 2003Lecture 316 How to identify? 1.Seek out multiple aggregate relationships from the same base 2.Determine appropriate type of relationship Backward or Forward containment Node 1 * children parent ComplexNode 1 * A B A B

17 January 13 2003Lecture 317 Consequences of Self-containing Backward specialized node contains links enables variable aggregation by subclass(es) Forward aggregate link is inherited watch for unexpected behavior! A B A B

18 January 13 2003Lecture 318 Relationship without containment Version Revision previous next 0..1 1

19 January 13 2003Lecture 319 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 January 13 2003Lecture 320 References none


Download ppt "Pick of the day 13-Jan-2003 Lecture 3 Common Patterns in Static Design."

Similar presentations


Ads by Google