Today. Last update: 5 June Structural Adapter Bridge Composite Decorator Façade Flyweight Proxy APPLICATION_1 APPLICATION_2. class APPLICATION_1

Similar documents
Flyweight Chain of Responsibility

Mechanical Design Patterns

Tecniche di Progettazione: Design Patterns

BFH/HTA Biel/DUE/Course 355/ Software Engineering 2. Suppose you ll write an application that displays a large number of icons:

Flyweight Pattern. Flyweight: Intent. Use sharing to support large numbers of fine-grained objects efficiently. CSIE Department, NTUT Chien-Hung Liu

Tecniche di Progettazione: Design Patterns

Design Patterns in PHP and Laravel

Generating None-Plans in Order to Find Plans 1

- 2 - Companion Web Site. Back Cover. Synopsis

2017 LOCKHEED MARTIN CORPORATION. ALL RIGHTS RESERVED

D-Case Modeling Guide for Target System

User Help. Fabasoft Scrum

01/26: Prototyping. Prototypes. Why? Answer Questions. Why? Determine Schedule. Speed (to Write) Why? Reduce Risk. Dr.

INF43: Introduction to Software Engineering. Instructor: Alex Thornton TA: Hye Jung Choi 4/24/2009

Transposition Table, History Heuristic, and other Search Enhancements

Robust Task Execution: Procedural and Model-based. Outline. Desiderata: Robust Task-level Execution

Non Functional Requirement (NFR)

Applied Econometrics with. Time, Date, and Time Series Classes. Motivation. Extension 2. Motivation. Motivation

Unchained Malady A Tangle of Times

PROGRAMMING LINX LEARNING GAME

Agile Methodology (Scrum Approach)

Pedestrian Dynamics: Models of Pedestrian Behaviour

ICS 606 / EE 606. RoboCup and Agent Soccer. Intelligent Autonomous Agents ICS 606 / EE606 Fall 2011

Adaptability and Fault Tolerance

beestanbul RoboCup 3D Simulation League Team Description Paper 2012

#19 MONITORING AND PREDICTING PEDESTRIAN BEHAVIOR USING TRAFFIC CAMERAS

Statewide Cycloplan: Bicycle Planning Tool & Participatory GIS

Pneumatic high-pressure controller Model CPC7000

Section 8: Model-View-Controller. Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian and Kellen Donohue

Better Search Improved Uninformed Search CIS 32

USER MANUAL

Helium: A Data Driven User Tool for SAR Analysis. May 17 th 2011 Karen Worsfold

Too Many VCLPlugs. Caolán McNamara, Red Hat Caolán McNamara

Neighborhood Design. City Council Update June 4, 2018

UNIQUE ADVANTAGES OF PIPENET

Scrum Portfolio jumshat.com

THE SOUNDBEAM 2 HANDBOOK PART 2 STEP BY STEP

Modeling Planned and Unplanned Store Stops for the Scenario Based Simulation of Pedestrian Activity in City Centers

Three-Dimensional Ray-Cast Pong

A Generalised Approach to Position Selection for Simulated Soccer Agents

in Hull Richard Green

Porting LibreOffice To GTK3

Learning of Cooperative actions in multi-agent systems: a case study of pass play in Soccer Hitoshi Matsubara, Itsuki Noda and Kazuo Hiraki

Decompression Method For Massive Compressed Files In Mobile Rich Media Applications

Bidirectional Forwarding Detection Routing

Ranger Walking Initiation Stephanie Schneider 5/15/2012 Final Report for Cornell Ranger Research

A physicist, an engineer and a programmer were in a car driving over a steep alpine pass when the brakes failed. The car was getting faster and

Circuit Lap Timer. The app has an Apple Watch interface for ios9+ and Watch OS2.0+. QuickStart Guide

LINEA LUCE PROFILE SERIES

Diver Training Options

The last of her species Further development at the Abidjan Zoo

Mac Software Manual for FITstep Pro Version 2

THE IN SITU PRESSURE CALIBRATION SYSTEM IN MÉTÉO FRANCE

SLIDES LINK -> PROJEKTOWANIE OPROGRAMOWANIA SYSTEMÓW

P r o j e c t M a n a g e M e n t f o r I n t e r a c t I v e D I g I t a l M e D I a

Flight Software Overview

VLSI Design 12. Design Styles

LegenDary 2012 Soccer 2D Simulation Team Description Paper

CMSC131. Introduction to Computational Thinking. (with links to some external Scratch exercises) How do you accomplish a task?

ISSUE #1 / SUMMER 2016

Transition from Scrum to Flow

Adaptation of Formation According to Opponent Analysis

Scrum Guide Revision

SIMULATION OF ENTRAPMENTS IN LCM PROCESSES

Pneumatic high-pressure controller Model CPC7000

An Indian Journal FULL PAPER ABSTRACT KEYWORDS. Trade Science Inc.

Agile project management with scrum

T H E R M O P T I M CALCULATION OF MOIST GAS FROM EXTERNAL CLASSES VERSION JAVA 1.5 R. GICQUEL MARCH 2007

An Architectural Approach for Improving Availability in Web Services

Bruno Cardoso UFMG, May 2014

Computer Integrated Manufacturing (PLTW) TEKS/LINKS Student Objectives One Credit

THE ARENA TABLE OF CONTENTS 6 THE ARENA OVERVIEW Dimensions and Tolerances... 2

Understanding safety life cycles

Interim Operating Procedures for SonTek RiverSurveyor M9/S5

IWR PLANNING SUITE II PCOP WEBINAR SERIES. Laura Witherow (IWR) and Monique Savage (MVP) 26 July

We release Mascot Server 2.6 at the end of last year. There have been a number of changes and improvements in the search engine and reports.

Getting Started with the LabVIEW Toolkit for LEGO MINDSTORMS NXT

Abseiling (Natural Surfaces) REGISTRATION LEVELS AND ASSESSMENT REQUIREMENTS

A GUIDE TO THE LOOSE ENDS HOCKEY LEAGUE WEBSITE PAGE

CS Lecture 5. Vidroha debroy. Material adapted courtesy of Prof. Xiangnan Kong and Prof. Carolina Ruiz at Worcester Polytechnic Institute

Site Improvements

Introducing STAMP in Road Tunnel Safety

NFRC U-FACTOR, SHGC, VT, & CONDENSATION RESISTANCE COMPUTER SIMULATION REPORT. (Revised) Rendered to: NORTH EAST WINDOWS, USA, INC.

Main Building and raft building viewed from the south side of the Oklahoma River. The white water Main Building anchors the development.

FireHawk M7 Interface Module Software Instructions OPERATION AND INSTRUCTIONS

SENSUS PRO MANAGER (for SENSUS or SENSUS PRO devices) User s Guide -- Windows. Version 2.0 Published October 17, ReefNet Inc.

Develop a Multi-Modal Transportation Strategy (Theme 6)

C o d i n g f o r i n t e r a C t i v e d i g i t a l M e d i a

UNDERSTANDING WALKING NETWORKS TO ENABLE SMARTER CHOICES IN TRANSPORT PLANNING IN DUNDEE. Gillian Iversen Atkins

Uninformed search methods II.

Integrate Riverbed SteelHead. EventTracker v8.x and above

LOST? EQUUS. How We Misunderstand the Nature of the Horse-Human Relationship Plus, Brave New Ideas for the Future

Configuring Bidirectional Forwarding Detection for BGP

Using MATLAB with CANoe

Introduction. The Shearwater Petrel is an advanced technical diving computer for open and closed circuit divers.

DRAFT for a State Policy for Healthy Spaces and Places

TECHNICAL NOTE HOW TO USE LOOPERS. Kalipso_TechDocs_Loopers. Revision: 1.0. Kalipso version: Date: 16/02/2017.

Systems Theoretic Process Analysis (STPA)

Newcastle Racecourse Masterplan. 1 Introduction. Completing the vision of a redeveloped Newcastle Racecourse Welcome to our exhibition.

Blackwave Dive Table Creator User Guide

Transcription:

Software Architecture Bertrand Meyer ETH Zurich, March-July 2007 Last update: 5 June 2007 Lecture 11: More patterns: bridge, composite, decorator, facade, flyweight Today Creational Abstract Factory Builder Factory Method Prototype Singleton Structural Adapter Bridge Composite Decorator Façade Flyweight Proxy Behavioral Chain of Responsibility Command (un/re) Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor Bridge pattern Bridge: Original pattern Decouple[s] an abstraction from its implementation so that the two can vary. [GoF, p 151] In other words: _something impl APPLICATION _something APPLICATION It separates the interface (visible to the clients) from the implementation (that may change later) APPLICATION_1 APPLICATION_2 APPLICATION_1 _something APPLICATION_2 _something Bridge: Classes Bridge: Classes deferred APPLICATION deferred APPLICATION APPLICATION_1 feature {NONE} -- Initialization (an_impl: like impl) is -- Set impl to an_impl. require an_impl /= Void impl := an_impl impl_set: an_impl = impl s _something is deferred inherit APPLICATION feature {NONE} -- Implementation impl: APPLICATION -- Implementation s _something is impl._something invariant impl_not_void: impl /= Void APPLICATION_1 APPLICATION APPLICATION_2 APPLICATION_1 APPLICATION APPLICATION_2 APPLICATION_1 inherit APPLICATION s _something is APPLICATION APPLICATION_1 APPLICATION_2 APPLICATION APPLICATION_1 APPLICATION_2

Bridge: Client view Bridge: A variation used in Vision2 CLIENT APPLICATION APPLICATION_1 APPLICATION_2 APPLICATION APPLICATION_1 APPLICATION_2 implementation EV_BUTTON interface EV_BUTTON_I s is local app1: APPLICATION_1 app2: APPLICATION_2 app1. ( {APPLICATION_1}) app1._something app2. ( {APPLICATION_2}) app2._something EV_TOGGLE _BUTTON interface EV_BUTTON EV_TOGGLE_BUT TON interface implementation EV_TOGGLE_ BUTTON_I interface Bridge: Vision2 example Bridge: Advantages (or when to use it) EV_BUTTON feature {EV_ANY, EV_ANY_I} -- Implementation implementation: EV_BUTTON_I -- Implementation feature {NONE} -- Implementation _implementation is {EV_BUTTON} implementation. (Current) No permanent binding between abstraction and implementation Abstraction and implementation extible by subing Implementation changes have no impact on clients Implementation of an abstraction completely hidden from clients Implementation share with several objects, hidden from clients Bridge: Componentization Non-componentizable (no library support) Composite pattern Way to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. [GoF, p 163]

Composite: Original pattern Transparency version Safety version _something _something _something i_th LEAF LEAF _something parts add remove has COMPOSITE _something i_th COMPOSITE parts _something add remove has Composite pattern, safety version (1/5) deferred _something is deferred feature -- Status report is_composite: BOOLEAN is -- Is component a composite? Result := False Composite pattern, safety version (2/5) Composite pattern, safety version (3/5) COMPOSITE inherit redefine is_composite, _from_components feature {NONE} -- Initialization is -- Initialize component parts. parts. _from_components (some_components: like parts) is -- Set parts to some_components. require some_components_not_void: some_components /= Void no_void_component: not some_components.has (Void) parts := some_components parts_set: parts = some_components feature -- Status report is_composite: BOOLEAN is -- Is component a composite? Result := True Composite pattern, safety version (4/5) Composite pattern, safety version (5/5) _something is from parts.start until parts.after loop parts.item._something parts.forth feature -- Access item: is -- Current part of composite Result := parts.item definition: Result = parts.item component_not_void: Result /= Void feature -- Others -- Access: i_th, first, last -- Status report: has, is_empty, off, after, before -- Measurement: count -- Element change: add -- Removal: remove -- Cursor movement: start, forth, finish, back feature {NONE} -- Implementation parts: LINKED_LIST [like item] -- Component parts -- (which are themselves components) invariant is_composite: is_composite parts_not_void: parts /= Void no_void_part: not parts.has (Void)

Composite: Variation used in EiffelMedia Composite: Advantages (or when to use it) EM_STRING EM_SPRITE EM_FIGURE EM_CLOSED _FIGURE EM_DRAW ABLE EM_BITMAP draw draw draw i_th EM_DRAWABLE _CONTAINER draw draw ext remove has Represent part-whole hierarchies Clients treat compositions and individual objects uniformly EM_CIRCLE draw EM_RECT ANGLE draw Composite: Componentization Fully componentizable Library support Main idea: Use genericity Composite: Pattern library version Transparency version _something i_th LEAF [G] _something parts add remove has COMPOSITE [G] _something Safety version _something _something LEAF [G] i_th COMPOSITE [G] parts _something add remove has Decorator pattern Decorator: Example Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subing for exting functionality. [GoF, p 175] draw draw TEXT_AREA DECORATED_ component draw COLOR color BORDERED_ AREA draw SCROLL_AREA draw

Decorator: Original pattern Decorator: Exporting additional features? SOME_ TYPE CONCRETE_ MY_DECORATED 1 attribute DECORATED_ component MY_DECORATED 1 Newly introduced features not need to be visible to clients, but they may. e.g. Display an area with a border of a certain color BORDERED_AREA inherit DECORATED_ feature color: COLOR set_color (a_color: like color) is draw is draw_border (color) component.draw Client can change the color by calling set_color if they have direct access to the BORDERED_AREA Decorator: Advantages (or when to use it) Decorator: Componentization Add responsibilities to individual objects dynamically and transparently Responsibilities can be withdrawn Omit explosion of subes to support combinations of responsibilities Non-componentizable Skeleton es can be generated Decorator skeleton, attribute (1/2) Decorator skeleton, attribute (2/2) indexing description: Skeleton of a component decorated with additional attributes DECORATED_ -- You may want to change the name. inherit -- You may need to change the name redefine -- List all features of that are not deferred. -- You may want to add creation procedures to initialize the additional attributes. feature {NONE} -- Initialization (a_component: like component) is -- Set component to a_component. require a_component_not_void: a_component /= Void component := a_component component_set: component = a_component -- List additional creation procedures taking into account additional attributes. feature -- Access -- List additional attributes. feature -- To be completed -- List all features from and implement them by -- delegating calls to component as follows: -- -- component.feature_from_component -- feature {NONE} -- Implementation component: -- Component that will be used decorated invariant component_not_void: component /= Void

Decorator skeleton, behavior (1/2) Decorator skeleton, behavior (2/2) indexing description: Skeleton of a component decorated with additional behavior DECORATED_ -- You may want to change the name. inherit -- You may need to change the name redefine -- List all features of that are not deferred. feature {NONE} -- Initialization (a_component: like component) is -- Set component to a_component. require a_component_not_void: a_component /= Void component := a_component component_set: component = a_component feature -- To be completed -- List all features from and implement them by -- delegating calls to component as follows: -- -- component.feature_from_component -- -- For some of these features, you may want to something more: -- -- component.feature_from_component -- _something_more -- feature {NONE} -- Implementation component: -- Component that will be used for the decoration invariant component_not_void: component /= Void Decorator skeleton: Limitations Facade feature -- To be completed -- List all features from and implement them by -- delegating calls to component as follows: -- -- component.feature_from_component -- Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that s the subsystem easier to use. [GoF, p 185] Does not work if feature_from_component is: an attribute: cannot redefine an attribute into a function (Discussed at ECMA) a frozen feature (rare): cannot be redefined, but typically: Feature whose behavior es not need to be redefined (e.g. standard_equal, from ANY) Feature defined in terms of another feature, which can be redefined (e.g. clone defined in terms of copy) Facade: Original pattern Facade: Example PROJECTOR CLIENT FACADE CLIENT ROOM_ FACADE close setup_projection setup_talk setup_break open WINDOW_ CONTROLLER DOOR_ CONTROLLER LIGHT_ CONTROLLER SHUTTER_ CONTROLLER internal Other example: Compiler, where clients should not need to know about all internally used es.

Facade: Advantages (or when to use it) Facade: Componentization Provides a simple interface to a complex subsystem Decouples clients from the subsystem and fosters portability Can be used to layer subsystems by using facades to define entry points for each subsystem level Non-componentizable Flyweight pattern Without the Flyweight pattern (1/2) Use sharing to support large numbers of fine-grained objects efficiently. [GoF, p 195] CLIENT draw_lines is -- Draw some lines in color. local line1, line2: LINE red: INTEGER line1. (red, 100, 200) line1.draw line2. (red, 100, 400) line2.draw Creates one LINE object for each line to draw Without the Flyweight pattern (2/2) With the Flyweight pattern (1/3) interface LINE feature -- Initialization (a_color, x, y: INTEGER) -- Set color to a_color, x as x_position, and y as y_position. color_set: color = a_color x_set: x_position = x y_set: y_position = y feature -- Access color: INTEGER -- Line color x_position, y_position: INTEGER -- Line position draw -- Draw line at position (x_position, y_position) with color. CLIENT draw_lines is -- Draw some lines in color. local line_factory: LINE_FACTORY red_line: LINE red: INTEGER red_line := line_factory.new_line (red) red_line.draw (100, 200) red_line.draw (100, 400) Creates only one LINE object per color

With the Flyweight pattern (2/3) With the Flyweight pattern (3/3) interface LINE_FACTORY feature -- Initialization new_line (a_color: INTEGER): LINE -- New line with color a_color new_line_not_void: Result /= Void interface LINE feature -- Initialization (a_color: INTEGER) is -- Set color to a_color. color_set: color = a_color feature -- Access color: INTEGER -- Line color draw (x, y: INTEGER) -- Draw line at position (x, y) with color. Shared/unshared and (non-)composite objects Flyweight: Original pattern The color of the LINE Two kinds of properties: Intrinsic characteristics stored in the flyweight Extrinsic characteristics moved to the client (typically a flyweight context ) get_flyweight FLYWEIGHT_ FACTORY flyweights FLYWEIGHT The coordinates of the LINE intrinsic_state _something CLIENT SHARED_ FLYWEIGHT UNSHARED_ FLYWEIGHT entire_state _something Flyweight pattern: Description Shared/unshared and (non-)composite objects Intent: Use sharing to support large numbers of finegrained objects efficiently. Participants: FLYWEIGHT: Offers a service _something to which the extrinsic characteristic will be passed SHARED_FLYWEIGHT: Adds storage for intrinsic characteristic COMPOSITE_FLYWEIGHT: Composite of shared flyweight; May be shared or unshared FACTORY: Creates and manages the flyweight objects CLIENT: Maintains a reference to flyweight, and computes or stores the extrinsic characteristics of flyweight Two kinds of flyweights: Composites (shared or unshared) Non-composites (shared)

Flyweight: Advantages (or when to use it) Flyweight pattern: Adapted pattern Reduces storage costs if a large number of objects is used through reducing the number of objects by using shared objects the amount of intrinsic state through computation of the extrinsic state Flyweight context Flyweight: Componentization External characteristics are not stored in the flyweight object client must handle them Fully componentizable A possibility is to a FLYWEIGHT_CONTEXT describing a list of flyweights grouped by FLYWEIGHT_ZONEs with the same external characteristic (e.g. characters with the same color in a row of a book page) Flyweight Library Flyweight Library: use of the Composite Library Mechanisms enabling componentization: constrained genericity, agents Factory Library and Composite Library Two kinds of flyweights: Non-composites (shared) Composites (shared or unshared) Use the Composite Library FLYWEIGHT [G] inherits from [FLYWEIGHT [G]] COMPOSITE_FLYWEIGHT [G, H] inherits from FLYWEIGHT [G] and COMPOSITE [FLYWEIGHT [G]] Uses the safety version of the Flyweight Library where the es not know about its parent to allow a same flyweight object to be part of different composites

What we ve seen today Bridge: Separation of interface from implementation Composite: Uniform handling of compound and individual objects Decorator: Attaching responsibilities to objects without subing Facade: A unified interface to a subsystem Flyweight: Using flyweight objects for reducing storage costs