Patterns for Decoupling

Similar documents
Coordination Patterns

A Metric of the Relative Abstraction Level of Software Patterns

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

Object-Oriented Software Development Goal and Scope

Design Patterns. Gunnar Gotshalks A4-1

Lecture 19: Introduction to Design Patterns

WS01/02 - Design Pattern and Software Architecture

Transparent Remote Access

A Metric for Measuring the Abstraction Level of Design Patterns

Introduction to Design Patterns

Cocoa Design Patterns. Erik M. Buck October 17, 2009

Universal Communication Component on Symbian Series60 Platform

Introduction to Design Patterns

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

Design Patterns. Architectural Patterns. Contents of a Design Pattern. Dr. James A. Bednar. Dr. David Robertson

Design patterns generic models

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Architectural Patterns

Towards Better Support for Pattern-Oriented Software Development

Distributed Proxy: A Design Pattern for Distributed Object Communication

Software-Architecture, Design Patterns and Refactoring An Overview

Design for Testability

Design Patterns. An introduction

CS560. Lecture: Design Patterns II Includes slides by E. Gamma et al., 1995

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

Broker Pattern. Teemu Koponen

Design Patterns. CSC207 Fall 2017

Design Patterns. CSC207 Winter 2017

Using Design Patterns in Java Application Development

Partial Acquisition Prashant Jain and Michael Kircher

Refining the Observer Pattern: The Middle Observer Pattern

Object-Oriented Design

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

Towards a Java Framework for Knowledge Representation and Inference

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

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

Programação de Sistemas Distribuidos

Patterns for Asynchronous Invocations in Distributed Object Frameworks

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Mining Relationships Between the Participants of Architectural Patterns

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

CS/CE 2336 Computer Science II

Crash course on design patterns

SOFTWARE PATTERNS. Joseph Bonello

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

DESIGN PATTERN - INTERVIEW QUESTIONS

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

A System of Patterns for Web Navigation

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

Data Synchronization Patterns in Mobile Application Design

Model-based Software Engineering (02341, spring 2016) Ekkart Kindler

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

Object-Oriented Design

Introduction and History

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

Patterns in Software Engineering

Topics in Object-Oriented Design Patterns

Chapter 12 (revised by JAS)

Object Design II: Design Patterns

Tuesday, October 4. Announcements

Initial contents proposal. List of topics. Common Architectural Styles. Architectural Styles. A sample from Elements of Software Architecture

3 Product Management Anti-Patterns by Thomas Schranz

Software Engineering

Patterns Architectural Styles Archetypes

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

Design Patterns. CSC207 Fall 2017

Design Patterns. Softwaretechnik. Matthias Keil. Albert-Ludwigs-Universität Freiburg

DESIGN PATTERNS DESIGN PATTERNS AND REUSABILITY

An Introduction to Patterns and Pattern Languages. Overview. Patterns -- Why? Patterns -- Why?

Design Patterns. Software Engineering. Sergio Feo-Arenis slides by: Matthias Keil

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Outline. Design Patterns. Observer Pattern. Definitions & Classifications

Applying the Observer Design Pattern

Architectural Patterns. Architectural Patterns. Layers: Pattern. Architectural Pattern Examples. Layer 3. Component 3.1. Layer 2

Architectural Patterns

Design Patterns Application with MDE

Reuse at Design Level: Design Patterns

An Introduction to Patterns

Design Patterns V Structural Design Patterns, 2

Design Patterns For Object Oriented Software Development Acm Press

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

A Safety Mechanism Using Software Patterns

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

Applying the Decorator Design Pattern

Adapter pattern. Acknowledgement: Freeman & Freeman

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

26.1 Introduction Programming Preliminaries... 2

Software Architecture

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Design Patterns! Acknowledgements!

CSE870: Advanced Software Engineering (Cheng) 1

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

Advanced Object Oriented PHP

C++ INTERFACE CLASSES STRENGTHENING ENCAPSULATION

Design patterns are partial solutions to common

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

RPC CLIENT: A PATTERN FOR THE CLIENT-SIDE IMPLEMENTATION OF

APICES - Rapid Application Development with Graph Pattern

Transcription:

Patterns for Decoupling Ingolf H. Krueger Department of Computer Science & Engineering University of California, San Diego La Jolla, CA 92093-0114, USA California Institute for Telecommunications and Information Technologies La Jolla, CA 92093-0405, USA

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 2

What are Patterns? A pattern for software architecture describes a particular recurring design problem that arises in specific design contexts, and presents a well-proven generic scheme for its solution. The solution scheme is specified by describing its constituent components, their responsibilities and relationships, and the ways in which they collaborate. [POSA96] Ingolf H. Krueger CSE 3

What are Patterns? Describes one proven solution for a recurrent design problem Defines the context for the solution s applicability adapted from [POSA96] Pattern Architectural Pattern Design Pattern Idiom coarse granularity fine Ingolf H. Krueger CSE 4

Design Patterns for Decoupling and Distribution Key steps during the design of components and their interfaces: Decoupling of strongly interdependent components Distribution of functions/data to other components Application of design patterns Ingolf H. Krueger CSE 5

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 6

Context & Problem Adapter A given component (target) offers the desired functionality The target's environment expects a different interface Solution: Define an adapter component that offers the required interface Associate the environment with the adapter instead of with the target Let the adapter relay calls from the environment to the target; adjust the relayed calls towards the interface of the target Let the adapter provide functions missing in the target Ingolf H. Krueger CSE 7

Adapter Structure: Environment «interface» DesiredInterface Service() TargetComponent TargetService() target 1 Adapter Service() Service() {return target.targetservice();} Ingolf H. Krueger CSE 8

Adapter Behavior: :Environment Service() :Adapter :TargetComponent TargetService() Ingolf H. Krueger CSE 9

Adapter Consequences: Enables reuse of target in different context Extension of functionality via the adapter potentially reduces the design s transparency If target becomes subcomponent of adapter: adjusting of all clients of target required to accommodate the adapter's interface Ingolf H. Krueger CSE 10

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 11

Context & Problem Decorator Modification of a target component s behavior is required The component s interface has to remain unchanged Solution: Define a decorator component that has the target s interface Store a reference to the target in the decorator Let the decorator relay calls to the target Let the decorator adjust the result obtained from the target to match the required modifications, and relay the adjusted result to the original caller Ingolf H. Krueger CSE 12

Decorator Structure: Environment «interface» Component Interface Service() component Component Decorator Service() Service() Service(){ component.service();...additional behavior... Decorator A Service()... Decorator Z Service() } Ingolf H. Krueger CSE 13

Decorator Behavior: :Environment :Decorator A :Decorator B :Component Service() Service() Service() additional Behavior() Ingolf H. Krueger CSE 14

Decorator Consequences: Flexible addition to/modification of component behavior Alternative to overloaded class hierarchies Communication overhead (potential performance loss) Ingolf H. Krueger CSE 15

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 16

Proxy Context & Problem Access to target component from several other components required Direct access to the target is impossible due to security, efficiency, or distribution requirements Solution: Define a placeholder (a proxy) that offers the same interface as the target component Make only the proxy known to the environment Let the proxy access the target, observing security, efficiency and distribution requirements Ingolf H. Krueger CSE 17

Proxy Structure: Environment «interface» Service Interface Service() ServiceProxy Service() target ServiceProvider Service() Ingolf H. Krueger CSE 18

Behavior: :Environment Proxy :ServiceProxy :ServiceProvider Service() pre() Service() post() Ingolf H. Krueger CSE 19

Proxy Consequences: Decoupling of service provider and service users Location of service provider is transparent to service users Proxy handles communication with service provider Applicable for decoupling of address spaces Increased communications overhead can reduce performance Ingolf H. Krueger CSE 20

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 21

Context & Problem Observer Several components depend on a target component s state All dependent components shall be informed about state changes of the target Loose coupling between dependent and target component target required Solution: Let all dependent components attach/register with the source Let components no longer interested in the target s state changes detach/unregister from the target In the event of a state change let the target send a notification message to all registered components Let the registered components inquire about the new state after they have been notified Ingolf H. Krueger CSE 22

Observer Structure: AbstractSource Attach(Observer) Detach(Observer) Notify() Source state GetState() SetState() 1 subject * observers for all o in observers { o.update(); } AbstractObserver Update() Observer Update() Ingolf H. Krueger CSE 23

Observer Behavior: :Source SetState() Notify() Update() o1:observer o2:observer GetState() Update() GetState() Ingolf H. Krueger CSE 24

Observer Consequences: Loose coupling between target and dependent components Support for event-based systems (multithreading) Design strategy for multicast-systems Problematic: Containment of update frequency Solution: apply multiple update strategies (strategy pattern) Ingolf H. Krueger CSE 25

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 26

Context & Problem MVC Application data needs to be maintained and presented via the user interface Multiple different output formats need to be supported Multiple different forms of input need to be supported How to establish consistency? Solution: Introduce separate components for storing and processing of data (model), data presentation (view), and for handling input (controller) The model represents the functional core; it registers dependent components (views and controllers) and notifies them about data changes The view retrieves data from the model and displays it The controller translates user input into events for the model; it may also change the UI to mirror data changes Ingolf H. Krueger CSE 27

MVC Structure: AbstractSource Attach(Observer) Detach(Observer) Notify() observers * AbstractObserver Update() Model 1 View Controller state model GetState() SetState() service() Update() Display() Initialize() Update() HandleInput() Initialize() Ingolf H. Krueger CSE 28

MVC Behavior: :Controller :Model :View HandleInput() Service() Notify() Update() GetState() Update() GetState() Display() Ingolf H. Krueger CSE 29

MVC Consequences: Decoupling of application data from presentation and input mechanism Consistency of user interface and underlying data model Increase of structural and dynamic complexity Potential loss of performance Ingolf H. Krueger CSE 30

Overview Recap: Patterns for Architecture and Design Adapter Decorator Proxy Observer Model-View-Controller Recursive Control Ingolf H. Krueger CSE 31

Context & Problem Recursive Control Decomposition of complex system into subsystems Subsystems have significant control part: Installation of new components at runtime System start, -initialization, -restart and -stop Fault diagnosis and -handling Performance monitoring Synchronization with environment... Control part overloads functional design Solution: Decoupling of control and function in every component Separation of interfaces for control and function Hierarchical composition Ingolf H. Krueger CSE 32

Recursive Control Structure: Control Interface Controller Controller Functional... Functional Component 1 Component n Functional... Component n 1 Functional Component n m Controller drives functional components Functional Interfaces Ingolf H. Krueger CSE 33

Recursive Control Structure: Controlled Comp LeafFunc Comp * General Comp 1 Control Part * Ingolf H. Krueger CSE 34

Behavior Recursive Control Usage of hierarchical state machines Controlled Comp activate LeafFunc Comp * Reset General Comp 1 Activating Control Part failure Failed * start start Stopped Operational stop Ingolf H. Krueger CSE 35

Recursive Control Behavior Usage of hierarchical state machines Control Aspects Functional Aspects activate Reset Activating failure Failed start start Stopped Operational stop Ingolf H. Krueger CSE 36

Recursive Control Behavior Usage of hierarchical state machines Control Aspects Functional Aspects lock locking activate idle lock Reset unlock Activating failure unlock Failed unlocking start start Stopped Operational stop Ingolf H. Krueger CSE 37

Example Applications: Control-Theory Telecommunication: Switches Consequences: failure activate Clear system structure Reset Activating Recursive Control Failed start start Separation of control from functional aspects Stopped Operational Controlled Comp stop Possible loss of performance due to distribution of control across hierarchical levels LeafFunc Comp General Comp Simplified design: use inheritance for control aspects * * 1 Control Part Func Comp 1 Func Comp 2 Ingolf H. Krueger CSE 38

Sources/References Adapter * Decorator * Proxy * Observer * Model-View-Controller + Recursive Control # * Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995 + Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, Michael Stal. Pattern- Oriented Software Architecture: A System of Patterns. Wiley, 1996 # Bran Selic. An Architectural Pattern for Real-time Control Software. In Vlissides, J.M., J.O. Coplien, and N.L. Kerth. (eds.): Pattern Languages of Program Design 2. Addison-Wesley, 1996. Ingolf H. Krueger CSE 39