Strategy and Template Method Patterns, Single User Protection

Slides:



Advertisements
Similar presentations
T O K ILL A S INGLETON F ACTORY M ETHOD P ATTERN Josh Mason 6/18/09.
Advertisements

SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Template Method By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
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.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
Pattern Hatching - John Vlissides Pages 85 – 101 Todd Anderson
Strategy Design Patterns CS 590L - Sushil Puradkar.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
The Factory Method Design Pattern Motivation: Class / Type separation – Abstract class serves as type definition and concrete class provides implementation.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Template Methods Ordering What We Do. Example - Solitaire Initialization of many solitaire games follow this pattern: Shuffle the cards Layout the game.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Stéphane Ducasse 1 Strategy.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
Design Engineering 1. Analysis  Design 2 Characteristics of good design 3 The design must implement all of the explicit requirements contained in the.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Copyright © Jim Fawcett Spring 2017
Design Patterns: MORE Examples
Data Abstraction: The Walls
Strategy: A Behavioral Design Pattern
Abstract Factory Pattern
Design Patterns: Brief Examples
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Chapter 4 The easy stuff.
Chapter 10 Design Patterns.
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Behavioral Design Patterns
Software Design and Architecture
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
More Design Patterns 1.
Multiuser Protection and the Mediator Pattern
More Design Patterns 1.
Jim Fawcett CSE776 – Design Patterns Summer 2003
Design for Ease in Contraction and Extension
CSE 432 Presentation GoF: Factory Method PH: “To Kill a Singleton”
More Object-Oriented Programming
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
DESIGN PATTERNS : Strategy Pattern
Strategy Design Pattern
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Overview of C++ Polymorphism
Informatics 122 Software Design II
Design by Abstraction (Continuation) CS 3331 Spring 2005
Design Patterns (Gamma, Helm, Johnson, Vlissides)
Composite Design Pattern By Aravind Reddy Patlola.
CSC 480 Software Engineering
Chapter 8 - Design Strategies
(4 – 2) Introduction to Classes in C++
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Strategy and Template Method Patterns, Single User Protection CSE432S Strategy and Template Method Patterns, Single User Protection 02/20/2006 CSE432S - Nick Beary

Strategy Pattern “Define a Family of Algorithms, encapsulate each one, and make them interchangeable.” 02/20/2006 CSE432S - Nick Beary

Strategy – The General Idea 3 Participants: Strategy, Context, Client (book has Strategy, ConcreteStrategy, Context). Client interacts with the same interface (Context), but has many options for algorithms (strategies). Context is the intermediary, but Client must have knowledge of Strategy 02/20/2006 CSE432S - Nick Beary

Strategy – Consequences Families of related algorithms An alternative to subclassing Strategies eliminate conditional statements A choice of implementations Clients must be aware of different Strategies Communication overhead between Strategy and Context Increased number of objects. 02/20/2006 CSE432S - Nick Beary

Strategy – Implementation Issues Defining the Strategy and Context interfaces Strategies as template parameters Making Strategy objects optional 02/20/2006 CSE432S - Nick Beary

Template Method Pattern “Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.” 02/20/2006 CSE432S - Nick Beary

Template Method – The General Idea 2 participants: AbstractClass and ConcreteClass Abstract Class defines parts of an algorithm that are invariant, leaves as virtual functions pieces of the algorithm that may or must be defined by Concrete Classes. The Hollywood Principle – Clever metaphor, or needless pun? 02/20/2006 CSE432S - Nick Beary

Template Method – Operations Concrete Operations Client class, Concrete Class Abstract Class Primitive Operations (abstract operations) Hook Operations Key Point: Distinguish operations which may be defined from those that must be defined. 02/20/2006 CSE432S - Nick Beary

Template Method – Implementation Issues Using C++ access control. Minimizing primitive operations Naming conventions 02/20/2006 CSE432S - Nick Beary

Single User Protection Time for some sweet, sweet Template Method Pattern Action! 02/20/2006 CSE432S - Nick Beary

Problems Write Protection Read Protection Note: File System Level How do we stop ourselves from making rash decisions about deletion and editing? Read Protection How do we keep things from our spouses and/or children? (Vlissides example, not mine) Note: File System Level 02/20/2006 CSE432S - Nick Beary

Write Protection Should prevent any changes to a node (relatively) Shouldn’t be able to be explicitly deleted, but protection might change at run-time, so can’t use const (C++). Solution: Protect the destructor! 02/20/2006 CSE432S - Nick Beary

Destructor Protection – Who Deletes? The Node class A class outside the Node class hierarchy Creates unnecessary friend status. A global function Really no benefit over a static member function. 02/20/2006 CSE432S - Nick Beary

Static or no? Syntax like node->destroy(); and delete this; unsettles some. Static member doesn’t support modification in subclasses. Non-virtual member function, employing everybody’s best friend… 02/20/2006 CSE432S - Nick Beary

TEMPLATE METHOD!!! Write a destroy method that takes care of invariant deletion functions, leave details to primitive operations/hooks. Primitives in this case include protection checking, warning actions, so forth. 02/20/2006 CSE432S - Nick Beary

Read Protection Add Templating to reading operations (i.e. streamOut). 02/20/2006 CSE432S - Nick Beary

Summary Strategy Pattern Template Method Pattern 1 Context, interchangeable interfaces Template Method Pattern Define Algorithm Invariant, leave primitives to subclasses Single-User Protection Use Template Method Pattern to apply security protocols, protect you from yourself and prying, ignorant others. 02/20/2006 CSE432S - Nick Beary