Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.

Slides:



Advertisements
Similar presentations
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Advertisements

Nov R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple.
2 Object-Oriented Analysis and Design with the Unified Process Objectives  Explain how statecharts can be used to describe system behaviors  Use statecharts.
Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype.
March R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (in Larman) Prototype Singleton.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Fall 2009ACS-3913 Ron McFadyen1 idea was first put forth by Christopher Alexander (1977) in his work on architectural design principles a pattern is a.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Fall 2009ACS-3913 R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) More GRASP Patterns.
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
Fall 2009ACS-3913 R McFadyen1 Singleton Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure.
NJIT Applying GOF Design Patterns Chapter 26 Applying UML and Patterns Craig Larman Presented By : Naga Venkata Neelam.
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.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Larman, chapters 25 and 26 CSE432 Object-Oriented Software Engineering Glenn D. Blank, Lehigh University Pure Fabrication and “Gang of Four” Design Patterns.
Design Patterns.
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
Chapter 17. GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities.
CSSE 374: Introduction to Gang of Four Design Patterns
CSSE 374: 3½ Gang of Four Design Patterns These slides derived from Steve Chenoweth, Shawn Bohner, Curt Clifton, and others involved in delivering 374.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Factory, Singleton & Strategy All References and Material From: Applying UML and Patterns, 3 rd ed, chpt 26 & 13 BTS530: Major Project Planning and Design.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
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.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), 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.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
OO Methodology Elaboration Iteration 2 - Design Patterns -
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Introduction
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.
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.
Object-Oriented Analysis and Design Week 12, 2009.
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Unit IV: GoF Design Patterns
Chapter 10 Design Patterns.
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Conception OBJET GRASP Patterns
Introduction to Design Patterns
Design Patterns (GoF) contains the creational patterns:
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Presented by Igor Ivković
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
Software Engineering Lecture 7 - Design Patterns
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Presented by Igor Ivković
GoF Patterns Ch. 26.
Presentation transcript:

Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative Development Part IV Elaboration Iteration II – More Patterns

Software Engineering 2 Object-oriented Analysis and Design Chap 26 Applying GoF Design Patterns

Software Engineering 3 Object-oriented Analysis and Design The Gang-of-Four Design Patterns  23 Gof Design Patterns.  perhaps 15 are common and most useful.  Book-- Design Patterns

Software Engineering 4 Object-oriented Analysis and Design  Name: Adapter  Problem: How to resolve incompatible interfaces, or provide a stable interface to similar components with different interfaces?  Solution: Convert the original interface of a component into another interface, through an intermediate adapter object.  Related Patterns: A resource adapter that hides an external system may also be considered a Facade object  Guideline: Include Pattern in Type Name Adapter (GoF)

Software Engineering 5 Object-oriented Analysis and Design Adapter (GoF) Figure The Adapter pattern.

Software Engineering 6 Object-oriented Analysis and Design Adapter (GoF) Figure Using an Adapter

Software Engineering 7 Object-oriented Analysis and Design Adapter and GRASP  Most design patterns can be seen as specializations of a few basic GRASP principles.  Underlying themes are more important

Software Engineering 8 Object-oriented Analysis and Design Factory  also called Simple Factory or Concrete Factory. This pattern is not a GoF design pattern.  It is also a simplification of the GoF Abstract Factory pattern  Name: Factory  Problem:Who should be responsible for creating objects when there are special considerations, such as complex creation logic, a desire to separate the creation responsibilities for better cohesion, and so forth?  Solution: Create a Pure Fabrication object called a Factory that handles the creation.  Related Patterns: Factories are often accessed with the Singleton pattern

Software Engineering 9 Object-oriented Analysis and Design Factory

Software Engineering 10 Object-oriented Analysis and Design Singleton (GoF)  it is desirable to support global visibility or a single access point to a single instance of a class  Name: Singleton  Problem: Exactly one instance of a class is allowedit is a "singleton." Objects need a global and single point of access.  Solution: Define a static method of the class that returns the singleton.  Related Patterns: The Singleton pattern is often used for Factory objects and Facade objectsanother GoF pattern that will be discussed.

Software Engineering 11 Object-oriented Analysis and Design Singleton (GoF) Figure The Singleton pattern in the ServicesFactory class

Software Engineering 12 Object-oriented Analysis and Design Singleton (GoF) public class Register { public void initialize() { … do some work … // accessing the singleton Factory via the getInstance call accountingAdapter = ServicesFactory.getInstance().getAcco untingAdapter(); … do some work … } // other methods… } // end of class public static synchronized ServicesFactory getInstance() { if ( instance == null ) { // critical section if multithreaded application instance = new ServicesFactory(); } return instance; } public class ServicesFactory { // eager initialization private static ServicesFactory instance = new ServicesFactory(); public static ServicesFactory getInstance() { return instance; } // other methods... }

Software Engineering 13 Object-oriented Analysis and Design Conclusion of the External Services with Varying Interfaces Problem

Software Engineering 14 Object-oriented Analysis and Design Strategy (GoF)  Name: Strategy  Problem: How to design for varying, but related, algorithms or policies? How to design for the ability to change these algorithms or policies?  Solution: Define each algorithm/policy/strategy in a separate class, with a common interface.  Related Patterns: Strategy is based on Polymorphism, and provides Protected Variations with respect to changing algorithms. Strategies are often created by a Factory.

Software Engineering 15 Object-oriented Analysis and Design Strategy (GoF) Figure Pricing Strategy classes Figure Strategy in collaboration

Software Engineering 16 Object-oriented Analysis and Design Strategy (GoF) Figure Context object needs attribute visibility to its strategy

Software Engineering 17 Object-oriented Analysis and Design Strategy (GoF)  Creating a Strategy with a Factory Figure Factory for strategies Figure Creating a strategy

Software Engineering 18 Object-oriented Analysis and Design Composite (GoF) and Other Design Principles  Name: Composite  Problem: How to treat a group or composition structure of objects the same way (polymorphically) as a non- composite (atomic) object?  Solution: Define classes for composite and atomic objects so that they implement the same interface.  Related Patterns: Composite is often used with the Strategy and Command patterns. Composite is based on Polymorphism and provides Protected Variations to a client so that it is not impacted if its related objects are atomic or composite.

Software Engineering 19 Object-oriented Analysis and Design Composite (GoF) and Other Design Principles Figure The Composite pattern

Software Engineering 20 Object-oriented Analysis and Design Composite (GoF) and Other Design Principles Figure Collaboration with a Composite

Software Engineering 21 Object-oriented Analysis and Design // superclass so all subclasses can inherit a List of strategies Public abstract class CompositePricingStrategy implements ISalePricingStrategy { protected List strategies = new ArrayList(); public add( ISalePricingStrategy s ) { strategies.add( s ); } public abstract Money getTotal( Sale sale ); } // end of class Composite (GoF) and Other Design Principles // a Composite Strategy that returns the lowest total // of its inner SalePricingStrategies public class CompositeBestForCustomerPricingStrategy extends CompositePricingStrategy { public Money getTotal( Sale sale ) { Money lowestTotal = new Money( Integer.MAX_VALUE ); // iterate over all the inner strategies for( Iterator i = strategies.iterator(); i.hasNext(); ) { ISalePricingStrategy strategy = (ISalePricingStrategy)i.next(); Money total = strategy.getTotal( sale ); lowestTotal = total.min( lowestTotal ); } return lowestTotal; } } // end of class

Software Engineering 22 Object-oriented Analysis and Design Composite (GoF) and Other Design Principles Figure Abstract superclasses, abstract methods, and inheritance in the UML

Software Engineering 23 Object-oriented Analysis and Design  Creating Multiple SalePricingStrategies Composite (GoF) and Other Design Principles Figure Creating a composite strategy

Software Engineering 24 Object-oriented Analysis and Design Composite (GoF) and Other Design Principles

Software Engineering 25 Object-oriented Analysis and Design Facade (GoF)  Name: Facade  Problem: A common, unified interface to a disparate set of implementations or interfacessuch as within a subsystemis required. There may be undesirable coupling to many things in the subsystem, or the implementation of the subsystem may change. What to do?  Solution: Define a single point of contact to the subsystema facade object that wraps the subsystem. This facade object presents a single unified interface and is responsible for collaborating with the subsystem components.  Summary: The Facade pattern is simple and widely used. It hides a subsystem behind an object.  Related Patterns: Facades are usually accessed via the Singleton pattern.

Software Engineering 26 Object-oriented Analysis and Design Facade (GoF)

Software Engineering 27 Object-oriented Analysis and Design Observer/Publish-Subscribe/Delegation Event Model (GoF)  Problem:

Software Engineering 28 Object-oriented Analysis and Design Observer/Publish-Subscribe/Delegation Event Model (GoF)  Name: Observer (Publish-Subscribe)  Problem: Different kinds of subscriber objects are interested in the state changes or events of a publisher object, and want to react in their own unique way when the publisher generates an event. Moreover, the publisher wants to maintain low coupling to the subscribers. What to do?  Solution: Define a "subscriber" or "listener" interface. Subscribers implement this interface. The publisher can dynamically register subscribers who are interested in an event and notify them when an event occurs. 

Software Engineering 29 Object-oriented Analysis and Design Observer/Publish-Subscribe/Delegation Event Model (GoF) Figure The Observer pattern

Software Engineering 30 Object-oriented Analysis and Design Observer/Publish-Subscribe/Delegation Event Model (GoF) Figure The observer SaleFrame1 subscribes to the publisher Sale Figure The Sale publishes a property event to all its subscribers

Software Engineering 31 Object-oriented Analysis and Design Observer/Publish-Subscribe/Delegation Event Model (GoF) Figure Who is the observer, listener, subscriber, and publisher?

Software Engineering 32 Object-oriented Analysis and Design Observer/Publish-Subscribe/Delegation Event Model (GoF) Figure Observer applied to alarm events, with different subscribers