Design Patterns (Gamma, Helm, Johnson, Vlissides)

Slides:



Advertisements
Similar presentations
GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Advertisements

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use.
Winter 2007ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
Computer Science 313 – Advanced Programming Topics.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Plab – Tirgul 12 Design Patterns
Strategy AKA Policy Dale Willey Ian Price. Overview Definitions Difference between Strategy pattern and strategy Where would you use this? Challenges.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
1 (More) Pattern Games CS : Software Design Winter /T10.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
The Template Method By Sinclair Schuller. What is the Template Method? “Skeleton” definition of an algorithm Allows redefinition of predetermined points.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
STRATEGY Object Behavioral Pattern. You are at the Pub two weeks before Fall Formal and still don’t have a date! All of a sudden a girl who you had a.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Spring 2010ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Chapter 1: Introduction to Design Patterns. SimUDuck Example.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
Case Studies on Design Patterns Design Refinements Examples.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
Y2 eProjects Session 4 – Advanced Topics. Objectives  Dynamic Models  Design Patterns (Optional)  Software testing (for S4) ACCP i7.1\Sem3_4\eProject\T4.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Strategy Design Patterns CS 590L - Sushil Puradkar.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1 Class 1-2.
Behavioral Pattern: Strategy C h a p t e r 5 – P a g e 205 The Open-Closed Principle advocates designing software in such a way that it will absorb new.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
SE-2811 Software Component Design Week 1, Day 2 (and 1-3 and 2-1) SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1.
Design Patterns: Elements of Reusable Object- Orientated Software Gamma, Helm, Johnson, Vlissides Presented By: David Williams.
An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant
The Strategy Design Pattern © Allan C. Milne v
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
Stéphane Ducasse 1 Strategy.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Introduction To Design Patterns
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Unit II-Chapter No. : 5- design Patterns
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Strategy Pattern.
Chapter Nine The Strategy Pattern
Factory pattern Unit of Work
Presented by Igor Ivković
SE-2811 Software Component Design
State Design Pattern 1.
Mediator Design Pattern (Behavioral)
عرض اجمالي المهام الشرطية في سي شارب (الأمر if)
SE-2811 Software Component Design
Design pattern Lecture 9.
Strategy and Template Method Patterns, Single User Protection
Strategy Design Pattern
Introduction to Design Patterns
Informatics 122 Software Design II
Design by Abstraction (Continuation) CS 3331 Spring 2005
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Software Design Lecture : 39.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Design Patterns (Gamma, Helm, Johnson, Vlissides) Strategy Define a family of algorithms, encapsulating each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Not to be confused with… Strategery Define a family of algorithmics, encapsulacating each one, and make them interjectionable. Strategery lets the algorithmic vary interdepartmentally from clients that use it. Design Patterns (Gamma, Helm, Johnson, Vlissides)

In normal words… If you have an object that can do something in many different ways, rather than putting each way into a method in the object and getting confused, put each way of performing the behavior in its own class.

Generic Strategy Pattern Declares interface common to all supported algorithms. Used by Context Configured with a ConcreteStrategy object. Maintains a reference to a Strategy object. Implements algorithm using Strategy interface Modified from Design Patterns (Gamma, Helm, Johnson, Vlissides)

PowerPoint Strategy Pattern (Example) Modified from Design Patterns (Gamma, Helm, Johnson, Vlissides)

Instead of this override PresentPowerpoint()

You have this PerfectPowerpoint PresentPerfectPowerpoint() AlrightPowerpoint PresentAlrightPowerpoint() LamePowerpoint PresentLamePowerpoint()

using System; using System. Collections. Generic; using System using System; using System.Collections.Generic; using System.Text; namespace StrategyExample { class Program static void Main() Presenter p = new Presenter(); p.SetPresentStrategy(new PerfectPowerPointPresentation()); p.Present(); p.SetPresentStrategy(new AlrightPowerPointPresentation()); p.SetPresentStrategy(new LamePowerPointPresentation()); Console.ReadKey(); }

abstract class PresentStrategy { public abstract void Present(); }   class PerfectPowerPointPresentation : PresentStrategy public override void Present() Console.WriteLine("Perfect: The presentation presented was incredible!!!"); class AlrightPowerPointPresentation : PresentStrategy Console.WriteLine("Alright: The presentation presented was just alright"); class LamePowerPointPresentation : PresentStrategy Console.WriteLine("Lame: The presentation presented was the one you’re watching now.");

class Presenter { private PresentStrategy _presentstrategy; public void SetPresentStrategy(PresentStrategy presentstrategy) this._presentstrategy = presentstrategy; } public void Present() _presentstrategy.Present(); Console.WriteLine();

Results from Example

Modified from Design Patterns (Gamma, Helm, Johnson, Vlissides) When do I use this? 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. In place of a conditional statement Modified from Design Patterns (Gamma, Helm, Johnson, Vlissides)