Design Patterns A General reusable solution to a commonly occurring problem in software design. Creational: Deal with object creation mechanisms – Example:

Slides:



Advertisements
Similar presentations
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Advertisements

Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Pattern Abstract Factory
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
BY VEDASHREE GOVINDA GOWDA
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Design Patterns.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
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.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Abstract Factory Design Pattern making abstract things.
Factory Method A Creational Design Pattern. Factory Method Key Features  Defines an interface for creating objects without needing to know each object’s.
Tech Talk Go4 Factory Patterns Presented By: Matt Wilson.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Mohammed Al-Dhelaan CSci 253 Object Oriented Design Instructor: Brad Taylor 06/02/2009 Factory Method Pattern.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
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.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Introduction
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Creational Patterns C h a p t e r 3 – P a g e 14 Creational Patterns Design patterns that deal with object creation mechanisms and class instantiation,
Factory Method. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we.
Design Patterns: MORE Examples
Strategy: A Behavioral Design Pattern
Design Patterns: Brief Examples
Unit II-Chapter No. : 5- design Patterns
Strategy Design Pattern
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Design Patterns C++ Java C#.
Low Budget Productions, LLC
Factory Patterns 1.
Interfaces.
Interface.
Design Patterns C++ Java C#.
Software Design and Architecture
Design Patterns with C# (and Food!)
object oriented Principles of software design
Object Oriented Analysis and Design
Software Engineering Lecture 7 - Design Patterns
Generation Gap By Kurt Rehwinkel
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
OOP Aga private institute for computer science 5th grade
Software Design Lecture : 28.
Presentation transcript:

Design Patterns A General reusable solution to a commonly occurring problem in software design. Creational: Deal with object creation mechanisms – Example: Abstract Factory Structural: Simplify design by identifying a simple way to realize relationships between entities. – Example: Bridge Behavioral: Identify common communication patterns between objects and realize these patterns. – Example: Strategy

Abstract Factory

Abstract Factory (Creational) Applying context: A client or application may want to use different types of objects with common behavior and easily change between those types before or during execution. Problem: Changing types of objects through the application is difficult because instantiation requires to know the type of object to be declared. Also different types might have different methods to use their functionality.

Abstract Factory (Creational) Solution: Isolate the client code from object creation by having client just ask for (and handle) a factory object. This factory object is an abstract data type which can only be used through an interface. Discussion: By having the client dependant just on the interface of the Abstract Type Product provided by the Abstract Factory. Each Concrete Product must be able to work under the interface that the Abstract Product provides. The client is able to change the Concrete Type Product by changing the Concrete Factory that is being used. This change is usually done by changing one line in one file.

Factory Classes

Product Classes

Client

Bridge Design Pattern

Problem The use of subclasses to provide additional implementation has caused the “hardening of the software arteries.” This limits the ability to independently extend the abstraction and the implementation.

UML Class Diagram

Purpose To “decouple abstraction from its implementation.” To “publish interface in an inheritance hierarchy, and bury implementation within it’s own inheritance hierarchy.”

Disadvantages Although it provides more flexibility, it increases the complexity of the software. Might have performance issues due to longer communication path between the abstraction and implementation.

Strategy Context: Your system has lots of different behaviors that can change in runtime and not easily manageable.

“Strategy”’s Strategy Separate behavior from implementation (encapsulate behavior). index.php?title=TheStrategyPattern /images/f/ff/Ff13-paradigm.jpg

class StrategyExample { public static void main(String[] args) { Context context; context = new Context(new ConcreteStrategyAdd()); int resultA = context.executeStrategy(3,4); context = new Context(new ConcreteStrategySubtract()); int resultB = context.executeStrategy(3,4); context = new Context(new ConcreteStrategyMultiply()); int resultC = context.executeStrategy(3,4); } } interface Strategy {int execute(int a, int b); } class ConcreteStrategyAdd implements Strategy { public int execute(int a, int b) { System.out.println("Called ConcreteStrategyAdd's execute()"); return a + b;} } class ConcreteStrategySubtract implements Strategy { public int execute(int a, int b) { System.out.println("Called ConcreteStrategySubtract's execute()"); return a - b;} } class ConcreteStrategyMultiply implements Strategy { public int execute(int a, int b) { System.out.println("Called ConcreteStrategyMultiply's execute()"); return a * b;} } class Context { private Strategy strategy; public Context(Strategy strategy) {this.strategy = strategy; } public int executeStrategy(int a, int b) { return strategy.execute(a, b); } }

Strategy v Bridge Same UML DiagramDifferent IntentStrategy = BehaviorBridge = Structure