OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Similar documents
OODP OOAD Session 7a

Object Oriented. Analysis and Design

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

What is Design Patterns?

What is Design Patterns?

What is Design Patterns?

Lecture 13: Design Patterns

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

Design patterns. OOD Lecture 6

An Introduction to Patterns

Object-Oriented Oriented Programming Factory Method Pattern Abstract Factory Pattern. CSIE Department, NTUT Woei-Kae Chen

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Second Midterm Review

2.1 Design Patterns and Architecture (continued)

CHAPTER 6: CREATIONAL DESIGN PATTERNS

From Design Patterns: Elements of Reusable Object Oriented Software. Read the sections corresponding to patterns covered in the following slides.

CS 2720 Practical Software Development University of Lethbridge. Design Patterns

2.1 Design Patterns and Architecture (continued)

The GoF Design Patterns Reference

GRASP 2. CSC 440: Software Engineering Slide #1

Object-Oriented Design

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

Design Patterns Cont. CSE 110 Discussion - Week 9

Lecture 20: Design Patterns II

Object-Oriented Design

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Lecture Material. Design Patterns. Visitor Client-Server Factory Singleton

Laboratorio di Tecnologie dell'informazione. Ing. Marco Bertini

GRASP Design Patterns A.A. 2018/2019

Factory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate

Creational Patterns for Variability

SDC Design patterns GoF

The Design Patterns Matrix From Analysis to Implementation

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

Design patterns. Jef De Smedt Beta VZW

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

Exam Questions. Object-Oriented Design, IV1350. Maximum exam score is 100, grade limits are as follows. Score Grade 90 A 80 B 70 C 60 D 50 E

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

Object-Oriented Design I - SOLID

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Design Pattern- Creational pattern 2015

An Introduction to Patterns

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

17. GRASP: Designing Objects with Responsibilities

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Object Oriented Design and Programming Revision

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.

Creational Design Patterns

2009 Shawn A. Bohner. Shawn Bohner Office: Moench Room F212 Phone: (812)

Brief Note on Design Pattern

CSC 301H, Introduction to Software Engineering

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

Design Patterns #3. Reid Holmes. Material and some slide content from: - GoF Design Patterns Book - Head First Design Patterns

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Creational Patterns. George Blankenship

Design Patterns Reid Holmes

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

Design Patterns (Part 2) CSCE Lecture 18-10/25/2016 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson)

Software Design COSC 4353/6353 D R. R A J S I N G H

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

Review Software Engineering October, 7, Adrian Iftene

Patterns and Testing

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)

Design Patterns Revisited

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

Responsibilities. Using several specific design principles to guide OO design decisions.

Tuesday, October 4. Announcements

Design Patterns. An introduction

11/12/12. Objectives DESIGN PATTERNS. Design Pattern. Defined Design Patterns. Applying Design Patterns. Motivating Example

GRASP ing at the First 5 Patterns Principles CSSE 574: Session 3, Part 4

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

A4 Explain how the Visitor design pattern works (4 marks)

Four More GRASP Principles CSSE 574: Session 5, Part 2

Behavioral patterns. Command Iterator Observer Strategy Template method

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Object-Oriented Design

Object-Oriented Concepts and Design Principles

Principles of Software Construction: Objects, Design and Concurrency. Object-Oriented Design: Assigning Responsibilities.

Lecture 21: Design Patterns III

Design Pattern and Software Architecture: IV. Design Pattern

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Patterns Continued and Concluded. July 26, 2017

18.1 Definitions and General OO Principles

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Design Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles

CHAPTER 6: CREATIONAL DESIGN PATTERNS

CS 247: Software Engineering Principles. Design Patterns

FACADE & ADAPTER CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 7 09/13/2011

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Transcription:

OODP Session 5a Next week: Reading week Session times PT group 1 Monday 18:00 21:00 room: Malet 403 PT group 2 Thursday 18:00 21:00 room: Malet 407 FT Tuesday 13:30 17:00 room: Malet 404 Email: oded@dcs.bbk.ac.uk Web Page: http://www.dcs.bbk.ac.uk/~oded Visiting Hours: Tuesday 17:00 to 19:00

Previously on OODP GRASP design patterns Information Expert Creator Low Coupling High Cohesion Controller (don t think in patterns, think patterns)

Classification (GoF Gang of Four) Creational Patterns Abstract object instantiation Structural Patterns Compose and organise objects into larger structures Behavioural Patterns Algorithms, interactions and control flow between objects.

Previously on OODF List of advanced patterns we already discussed Strategy (behavioural) List of advanced patterns for today Adapter (structural) Decorator (structural) Factory Method (Creational) Abstract Factory (Creational) Singleton (Creational)

Adapter

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

Class Adapter How: Inheritance client Target Adaptee request() specificrequest() (implementation) Adapter request() All the Gluing code

Object Adapter How: Inheritance + delegation client Target request() Adaptee specificrequest() Adapter adaptee request() All the Gluing code

Discussion Why Use? Want to use other people code Not just use other peoples code but override some of it Class Adapter advantages: Simpler Class Adapter Issues Works only for one specific class and not its subclasses Object Adapter Issues Harder to override adaptee behaviour

Decorator

House, (partial) Domain Model Room Living Room Bed Room Kitchen Bath Room Problem: How can we add responsibilities to rooms?

Room, Add Responsibilities Room Living Room Bed Room Kitchen Bath Room Naïve idea: Just add the required methods to all classes What if? Someone else s classes and you don t want to change them Don t want to add responsibilities to all subclasses Want the decision of adding the functionality to be in run time

Airplane Game, Decorator Not so naïve anymore What needs to happen? What can we do? New class with the same interface (Decorator) Encapsulation Room Decorator

Decorator Pattern Problem: How can we add responsibilities to airplanes? Component operation() ConcreteComponent operation() Decorator operation() addedbehaviour() ConcreteDecoratorA addedattribute operation() ConcreteDecoratorB operation() addedbehaviour()

Decorator Pattern Pros Classes remain light weight More flexibility Cons More classes Decorator and components aren t identical

Factory Method

Square subclasses in the Monopoly Game In the monopoly game there are different classes of squares. Say it only has a single abstract class as an attribute. Regretfully the actual choice of class depends on the subclass of square

Factory Method Idea: Instead of using new inside the constructor, use a dedicated method (factorymethod) Override this method in subclasses Method may also get a parameter as input Product Creator factorymethod() ConcreteCreator ConcreteProduct factorymethod()

Abstract Factory

Monopoly Game GUI It has become fashionable to let the user control the look-and-feel of GUI s. Why not have this in our monopoly game. Problem: the look and feel of the monopoly game depends on many different objects. Idea different objects come from different factories

Abstract Factory AbstractFactory CreateProductA() CreateProductB() AbstractProductA ConcreteProductA1 ConcreteProductA2 AbstractFactory1 CreateProductA() CreateProductB() AbstractFactory2 CreateProductA() CreateProductB() AbstractProductB ConcreteProductB1 ConcreteProductB2 Doesn t this add a lot of coupling?

Singleton

Singleton Structure: Intent: Ensure a class has one instance, and provide a global point of access to it.

Singleton Example Public class PrintSpooler { // a prototype for a spooler class, // such that only one instance can ever exist private static PrintSpooler _spooler; private PrintSpooler() { /* private constructor */ } public static synchronized getspooler() { if (_spooler == null) _spooler = new PrintSpooler(); return _spooler; } } class Main { // example of use public static void main(string args[]) { PrintSpooler spl =PrintSpooler.getSpooler(); spl.print ("Printing data"); } }

Back to GRASP

More GRASP patterns Information Expert, Creator, Low Coupling, High Cohesion, Controller Polymorphism Indirection Pure Fabrication Protected Variations

Polymorphism

Pattern Name: Polymorphism Problem It Solves: How to handle alternatives based on type? How to create pluggable software components? Solution: When related alternatives or behaviour vary by type, assign responsibilities for the behaviour using polymorphism Alternatives based on type replacing code by classes and types Pluggable software components viewing components in client server relationships, how can you replace one server component with another without affecting the client

Where have we seen Polymorphism GoF Design Patterns: Strategy Abstract Factory

Indirection

Pattern Name: Indirection Problem It Solves: Where to assign a responsibility, to avoid direct coupling between two or more things Solution: Assign the responsibility to an intermediate object

Where have we seen Indirection GoF Design Patterns: Strategy Abstract Factory

Pure Fabrication

Pattern Name: Pure Fabrication Problem It Solves: What object should have the responsibilities, when you don t want to violate high cohesion and low coupling, or other goals, but solutions offered by Expert (for example) are not appropriate. Solution: Assign a highly cohesive set of responsibilities to an artificial class that does not represent a problem domain concept (such a class is a fabrication of the imagination).

Where have we seen Pure Fabrication GoF Design Patterns: Strategy Abstract Factory

Protected Variation

Pattern Name: Protected Variation Problem It Solves: How to design objects, subsystems, and systems so that the variations or instability in these elements does not have an undesirable impact on other elements? Solution: Identify points of predicted variation or instability; assign responsibilities to create a stable interface around them.

Where have we seen Protected Variation GoF Design Patterns: Strategy Decorator Abstract Factory...