Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.

Slides:



Advertisements
Similar presentations
Creational Design Patterns. Creational DP: Abstracts the instantiation process Helps make a system independent of how objects are created, composed, represented.
Advertisements

Creational Patterns (2) CS350/SE310 Fall, Lower the Cost of Maintenance Economic Goal Coupling-Cohesion, Open-Close, Information-Hiding, Dependency.
Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Creational Patterns - Page L4-1 PS95&96-MEF-L11-1 Dr. M.E. Fayad Creationa l Paradigm.
Plab – Tirgul 12 Design Patterns
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Patterns.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
Case Studies on Design Patterns Design Refinements Examples.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
Creational Patterns (1) CS350, SE310, Fall, 2010.
02 - Creational Design Patterns Moshe Fresko Bar-Ilan University תשס"ח 2008.
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
GoF: Document Editor Example Rebecca Miller-Webster.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Creational Patterns CSE Creational Patterns Class creational pattern ◦ uses inheritance to vary the class that is instantiated Object creational.
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.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
Advanced Object-oriented Design Patterns Creational Design Patterns.
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:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
 Creational design patterns abstract the instantiation process.  make a system independent of how its objects are created, composed, and represented.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
The Abstract Factory Pattern (Creational) ©SoftMoore ConsultingSlide 1.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
S.Ducasse Stéphane Ducasse 1 Adapter.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
S.Ducasse Stéphane Ducasse 1 Abstract Factory.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Design Patterns: MORE Examples
Abstract Factory Pattern
Design Patterns: Brief Examples
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Factory Patterns 1.
Software Design and Architecture
object oriented Principles of software design
Abstract Factory Pattern
Presented by Igor Ivković
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Creational Patterns.
Informatics 122 Software Design II
Presented by Igor Ivković
Adapter Pattern Jim Fawcett
Adapter Pattern Jim Fawcett
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides

Adapter Synopsis: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Context: You want to use an existing class whose interface does not match the one you need.

Adapter: motivating example Example: A Drawing Editor that operates with various Shapes:(Line and TextShape). Interface (set of services) to each subclass of Shape is predefined. Would like to use an off-the-shelf implementation, TextView, for dealing with the text, but TextView uses a different interface, and thus, cannot be used in a straightforward way. Solution: Define TextShape so that it adapts TextView 1. Class Adapter: TextShape inherits interface from Shape and inherits implementation from TextView 2. Object Adapter: TextShape includes a TextView Object. Each service of TextShape is implemented using the appropriate service of TextView.

Object Adapter Off-the-shelf implementation. Source code is unavailable Original design specifies the interface to all Shapes

Object Adapter Compose the existing object (the Adaptee) within an Adaptor object that implements the desired interface. The Adapter forwards to the subject while possibly performing additional actions.

Another Solution: Class Adapter Adapter inherits the interface from the Target and the implementation from Adaptee

Strategy Synopsis: Define a family of algorithms, encapsulate each one and make them interchangeable. Strategy lets the algorithm vary independently from clients that use them. Context: Need to provide a way of configuring a class with one of many behaviors, or Need different versions of an algorithm, for example, for different time/memory constraints, or Need to hide a lot of complex algorithm-specific implementation details

Strategy Abstract class, declares an interface common to all supported algorithms. Context uses this interface to call the algorithm defined by a ConcreteStrategy Each ConcreteStrategy implements the algorithm using the Strategy interface

Strategy: example Need to implement different strategies for a character in a game scenario, depending on difficulty level. Context - TetrisBoard Abstract class - BlockDropStrategy Concrete classes - DropStrategyLevel-1… DropStrategyLevel-N

Abstract Factory Synopsis: provide an interface for creating families of related or dependent objects without specifying their concrete classes. Motivating example: Consider a user interface toolkit that supports multiple look-and-feel standards Requires portability across different look-and-feel standards, different widgets (buttons, scroll bars, etc.) should not be hard coded for a particular look-and-feel.

Abstract Factory Solution: abstract WidgetFactory class, defines interface for creating each kind of widget, abstract class for each kind of widget, with concrete classes implementing different look-and-feel standards

Abstract Factory for Widgets Notation: AB means A creates (instantiates) B

Abstract Factory Declares an interface for creating product objects Implement creation concrete products for each “version” Declare interface for product Implement concrete product

Abstract Factory Hides the knowledge of which concrete classes are used Hides how instances are created and put together All the system knows - is the interfaces of abstract classes This provides a lot of flexibility and make the system “configurable” at either compilation or run time.

Abstract Factory: Applicability Use when a system should be independent of how its components are created a system must be configured with one of multiple families of products a family of related products are designed to work together and you need to enforce that you want to provide a class library of products, and you want to reveal just their interfaces, not implementation

Maze Problem Context: build a maze for a game. Maze is a set of rooms. Each room knows 4 neighbors Neighbor is a door, a wall or another room To create a maze - must create a set of rooms

Maze Extend the design to be able to create an enchanted maze as well as the regular maze. Enchanted maze may have enchanted rooms -- rooms which have magic keys inside doors that can be opened only with a magic key in addition to regular rooms,doors and walls.

Maze, continued... Hardcoding the layout of the maze in the maze constructor is inflexible - need a separate constructor for every configuration. Builder pattern allows to construct a maze based on a given configuration.