and professional practice l8.5: object-oriented design...
TRANSCRIPT
Design Patterns 1
Software Developmentand Professional Practice
L8.5: Object-Oriented Design - Have I got a Strategy!
Intro to Development 2
Unless otherwise expressly stated, all original material of whatever nature created by John F. Dooley and included in this web site and any related pages, including the site's archives, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Design Patterns 3
SimUDuck!
Design Patterns 4
Design Patterns
Now we want to fly!
So how to add flying to SimUDuck?
5
Design Patterns
Is this OK? Looks OK, right? So now we can add more ducks, right?
6
What don’t these ducks do?
Design Patterns
So what to do?
Anything wrong with this?
So, inheritance might not be the right thing to use here Sound familiar?
7
Design Patterns
Back to OO Design principles...
take the parts of your system that vary and encapsulate them, so that later you can alter or extend the parts that vary without affecting those that don’t.
8
Design Patterns
So what changes?
9
Design Patterns
So what changes?
10
Design Patterns 11
Design Patterns
So for the Ducks...
12
Design Patterns 13
Design Patterns 14
Design Patterns
Final version...
15
Design Patterns
And so what have we learned?
16
Design Patterns
Applicability of Strategy
Use the Strategy pattern when many related classes differ only in their behavior. you need different variants of an algorithm. an algorithm uses data that clients shouldn’t know
about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures.
a class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class.
(all this directly from GoF, page 316.)
17
Design Patterns 18
References Freeman, Eric and Freeman, Elisabeth, Head First Design
Patterns, O’Reilly, 2004. Dooley, John F., Software Development and Professional
Practice, Apress, 2011.