ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.

Slides:



Advertisements
Similar presentations
UMBC Some Additional Patterns CMSC 432. UMBC More Patterns2 Introduction Over the next few lectures we’ll have an introduction to a number of patterns.
Advertisements

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 1 Mediator Abbas Rasoolzadegan.
Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
(A Completely Colorless Powerpoint Presentation of) The Interpreter Pattern David Witonsky.
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
Design Patterns In OPM Presented by: Galia Shlezinger Instructors: Prop. Dov Dori, Dr. Iris Berger.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Template Method By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
Mediator A Behavioral Design Pattern for the New Millennium Cory Nugent.
Algorithm Programming Behavioral Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Interpreter By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
Reuse Activities Selecting Design Patterns and Components
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
The Interpreter Pattern. Defining the Interpreter Intent Given a language, define a representation for its grammar along with an interpreter that uses.
BY VEDASHREE GOVINDA GOWDA
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
A Behavior Object Pattern
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
More Design Patterns In Delphi Jim Cooper Falafel Software Session Code: D3.03 Track: Delphi.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
© Spiros Mancoridis 27/09/ Software Design Topics in Object-Oriented Design Patterns Material drawn from [Gamma95] and [Coplien95] Revised and augmented.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
DESIGN PATTERNS -BEHAVIORAL PATTERNS WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
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:
Interpreter By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Jim Fawcett CSE776 – Design Patterns Summer 2006
Design Patterns: MORE Examples
Mediator Design Pattern
Chapter 10 Design Patterns.
Introduction to Design Patterns
Behavioral Design Patterns
Software Design and Architecture
Observer Design Pattern
object oriented Principles of software design
Presentation by Julie Betlach 7/02/2009
Mediator Design Pattern (Behavioral)
Informatics 122 Software Design II
Object Oriented Design Patterns - Behavioral Patterns
Interpreter Pattern.
Strategy and Template Method Patterns, Single User Protection
Informatics 122 Software Design II
Presentation transcript:

ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap

ECE450 - Software Engineering II2 The Interpreter pattern Need to know it exists, but it is probably the pattern with the lowest general applicability of all –Though it’s very helpful if you deal with language creation, allowing users to come up with domain formulas, small compilers, etc. Interpreter: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language Example: Regular expressions –The Interpreter pattern uses a class to represent each grammar rule... I.e., what constitutes an “expression”, a “literal”, etc. –...and a Composite structure to construct the language

ECE450 - Software Engineering II3 Structure and participants AbstractExpression –Declares an abstract Interpret operation that is common to all nodes in the abstract syntax tree TerminalExpression –Implements an Interpret operation associated with terminal symbols in the grammar –An instance is required for every terminal symbol in a sentence NonterminalExpression –One such class is required for every rule in the grammar –Implements an Interpret operation for nonterminal symbols, typically calling itself recursively on the variables of the rule Context –Contains information that is global to the interpreter Client –Builds, or is given, an abstract syntax tree representing a sentence in the language that the grammar defines –Invokes the Interpret operation

ECE450 - Software Engineering II4 Applicability Use Interpret when there is a language to interpret, and you can represent statements in the language as abstract syntax trees. It works best when: –The grammar is simple (otherwise the class hierarchy may become unmanageable) –Efficiency is not a critical concern

ECE450 - Software Engineering II5 Consequences It’s easy to change and extend the grammar –...since it uses classes to represent grammar rules Complex grammars are hard to maintain –The pattern defines at least one class for every rule in the grammar. Grammars containing many rules can be hard to manage and maintain. Adding new ways to interpret expressions –It’s easier to evaluate an expression in a new way (e.g., pretty printing) –If you keep creating new ways of interpreting an expression, consider using Visitor to avoid changing the grammar classes

ECE450 - Software Engineering II6 Coordinating GUI objects

ECE450 - Software Engineering II7 How can we coordinate the interactions of all those objects? Idea #1: Each object notifies of its changes directly to those that would be interested –For example, the Font list lets the Outline checkbox know whether it should be disabled –Too tight coupling! Idea #2: Implement Observer –Every object has a list of Observers and notifies them of changes Objects don’t need to know the details of who is observing them......nor how the change will impact others –Much better approach... –...but a bit clumsy: Every object is both an observer and a subject! Idea #3: The Mediator pattern –Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently

ECE450 - Software Engineering II8 The mediator sits in the middle of all interactions

ECE450 - Software Engineering II9 Structure and Participants Mediator –Defines an interface for communicating with Colleague objects ConcreteMediator –Implements cooperative behavior by coordinating Colleague objects Colleague classes –Each Colleague class knows its Mediator object –Each colleague communicates with its mediator whenever it would have otherwise communicated with another colleague

ECE450 - Software Engineering II10 Applicability Use the Mediator pattern when... –A set of objects communicate in well-defined but complex ways. The resulting interdependencies are unstructured and difficult to understand –Reusing an object is difficult because it refers to and communicates with many other objects –A behavior that’s distributed between several classes should be customizable without a lot of subclassing

ECE450 - Software Engineering II11 Consequences It limits subclassing –Mediator localizes behavior that otherwise would be distributed among several objects. Changing this behavior requires subclassing Mediator only; Colleagues can be reused as is It decouples colleagues It simplifies object protocols –Replaces many-to-many interactions with one-to-many interactions between the mediator and its colleagues It abstracts how objects cooperate –Since all mediation happens through a single object, it helps clarify how objects interact It centralizes control –Trades complexity of interaction for complexity in the mediator –May become more complex than any individual colleague

ECE450 - Software Engineering II12 Implementation Do we need the abstract Mediator class? –We do not need it when colleagues work with only one mediator How can we implement the Colleague-Mediator communication? –We can implement the Mediator as an Observer of all the Colleagues Instead of having everyone be both an Observer and a Subject

ECE450 - Software Engineering II13 Finishing the tour at the beginning... Remember our old pizza example? –When we started this topic, we discussed the Template Method pattern, but we never defined it nor explained it properly –It’s the only pattern left to define from the original Design Patterns book –...so let’s get through with it: Template Method: Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure

ECE450 - Software Engineering II14 Example recap

ECE450 - Software Engineering II15 Participants and structure AbstractClass –Defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm –Implements a template method defining the skeleton of an algorithm ConcreteClass –Implements the primitive operations to carry out subclass-specific steps of the algorithm

ECE450 - Software Engineering II16 Applicability Use the Template Method pattern... –To implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behavior that can vary –When common behavior among subclasses should be factored and localized in a common class to avoid code duplication “Refactoring to generalize” –To control subclasses extensions You can define a template method that calls “hook” operations at specific points, thereby permitting extensions only at those points

ECE450 - Software Engineering II17 Consequences Fundamental technique for code reuse –Particularly important in class libraries, since they are the means for factoring out common behavior in library classes Lead to an inverted control structure sometimes referred to as “the Hollywood principle” –“Don’t call us, we’ll call you” –The parent class calls the operations of a subclass and not the other way around