25-patternsofpatterns

25-patternsofpatterns - Patterns of Patterns Kenneth M....

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Patterns of Patterns Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 — Lecture 25 — 11/17/2009 © University of Colorado, 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Goals • Cover Material from Chapter 12 of the Design Patterns Textbook 2
Background image of page 2
Patterns of Patterns • Patterns can be • used together in a single system (we’ve seen this several times) • can be combined to create, in essence, a new pattern • Chapter 12 does a good job of showing both of these situations in use • DuckSimulator Revisited: An example that uses six patterns at once • Model View Controller: A pattern that makes use of multiple patterns • We’ll see many examples as we move through this lecture 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
But frst… what pattern is this? regBar(Bar) remBar(Bar) notBars() Foo «Interface» heyYou() Bar «Interface» bars * getSecret() setSecret() secret_data RealFoo RealBar foo Remember that the names of classes participating in a pattern is unimportant; Its the structure (of the relationships and methods) that’s important! 4
Background image of page 4
Duck Simulator Revisited • We’ve been asked to build a new Duck Simulator by a Park Ranger interested in tracking various types of water fowl, ducks in particular. • New Requirements • Ducks are the focus, but other water fowl (e.g. Geese) can join in too • Need to keep track of how many times duck’s quack • Control duck creation such that all other requirements are met • Allow ducks to band together into Focks and subFocks • Generate a noti±cation when a duck quacks • Note: to avoid coding to an implementation, replace all instances of the word “duck” above with the word “Quackable” 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Opportunities for Patterns • There are several opportunities for adding patterns to this program • New Requirements Ducks are the focus, but other water fowl (e.g. Geese) can join in too (ADAPTER) Need to keep track of how many times duck’s quack (DECORATOR) Control duck creation such that all other requirements are met (FACTORY) Allow ducks to band together into Focks and subFocks (COMPOSITE and ITERATOR) Generate a noti±cation when a duck quacks (OBSERVER) • Lets take a look at this example via a class diagram perspective 6
Background image of page 6
Step 1: Need an Interface quack() Quackable «interface» All simulator participants will implement this interface 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Step 2: Need Participants Interloper! quack() Quackable «interface» MallardDuck RedheadDuck DuckCall RubberDuck honk() Goose 8
Background image of page 8
Step 3: Need Adapter quack() Quackable «interface» MallardDuck RedheadDuck DuckCall RubberDuck honk() Goose GooseAdapter goose All participants are now Quackables, allowing us to treat them uniformly 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Review: (Object) Adapter Structure Client request() Target «interface» request() Adapter specifcRequest() Adaptee adaptee.specifcRequest() Quackable Goose GooseAdapter quack() { goose.honk() } 10
Background image of page 10
Step 4: Use Decorator to Add Quack Counting quack() Quackable «interface» quack() static getQuacks(): int QuackCounter
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CSCI 5448 taught by Professor Anderson during the Fall '09 term at Colorado.

Page1 / 29

25-patternsofpatterns - Patterns of Patterns Kenneth M....

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online