Mediator Pattern

Total Page:16

File Type:pdf, Size:1020Kb

Mediator Pattern Mediator Pattern a.k.a. Broker a.k.a. Vermittler 1 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Beschreibung Hochschule Konstanz Klifikilassifikation: Obje kt bas iertes Verhlhaltensmuster ZkZweck: Wenn eine Menge von Obje kten untitereinan der kommunizieren wird eine Indirektion eingebaut d.h. die Objekte reden nicht mehr direkt miteinander sondern indirekt über den „Mediator“ / „Vermittler“. "Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently." (Gamma et al., 1995) 2 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Motivation Hochschule Konstanz Vorher: Kollege Kollege Kollege Kollege Kollege 3 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Motivation Hochschule Konstanz Nachher: Kollege Kollege Vermittler Kollege Kollege Kollege 4 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Motivation / Beispiel Hochschule Konstanz Chat: Viele Anwender (Collegues) unterhalten sich: ‐ Ungünstig alle untereinander zu verbinden ‐ MditMediator itist der Cha troom Fluglotsen: ‐ Flugzeuge (Collegues) können sich nicht alle untereinander verständigen Æ Kontrollcenter 5 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Struktur Hochschule Konstanz 6 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Struktur Hochschule Konstanz Beispiel Flugverkehr: 7 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Struktur Hochschule Konstanz Beispiel Flugverkehr: 8 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Teilnehmer Hochschule Konstanz Mediator ‐ defines the interface for communication between Colleague objects Concrete Mediator ‐ implements the Mediator interface and coordinates communication between Colleague objects. It is aware of all the Colleagues and their purpose with regards to inter communication. Concrete Colleague ‐ communicates with other Colleagues through its Mediator 9 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Beschreibung II Hochschule Konstanz Abstrakte Vermittler / Interface Abstrakte Mediatoren /Interfaces werden nicht benötigt wenn nur ein Mediator verwendet wird. Sie werden benötigt wenn mehrere unterschiedliche Mediatoren zum Einsatz kommen. 10 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Pro vs. Kontra Hochschule Konstanz Pro: ‐ Einfacheres Verständnis der Logik im System da es an einer zentralen Stelle gesammelt ist ‐ Lose Kopplung: Es können leicht neue Kollegen hinzugefügt, entfernt oder geändert werden. ‐ Nur noch 1‐n Beziehungen statt m‐n. ‐ Einfach erweiterbar: wenn neue Logik benötigt wird kann von dem Mediator/Vermittler einfach vererbt werden Kontra: ‐ Bei vielen Teilnehmern kann es zu sehr kompliziertem Inhalt/Logik des Mediators kommen Æ schwierig zu verstehen bzw. zu ändern ‐ Sing le point of filfailure: wenn der VilVermittler ausfällt, fällt das gesamte System aus ‐ Skalierbarkeit 11 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Verwandte Muster Hochschule Konstanz Facade Pattern ‐ a simplified mediator becomes a facade pattern if the mediator is the only active class and the colleagues are passive classes. A facade pattern is just an implementation of the mediator pattern where mediator is the only object triggering and invoking actions on passive colleague classes. The Facade is being called by some external classes. Adapter Pattern ‐ the mediator patter just "mediate" the requests between the colleague classes. It is not supposed to change the messages it receives and sends; if it alters those messages then it is an Adapter pattern. Observer Pattern ‐ the observer and media tor are siilimilar patterns, solving the same problem. The main difference between them is the problem they address. The observer pattern handles the communication between observers and subjects or subject. It's very probable to have new observable objects added. On the other side in the mediator pattern the mediator class is the the most likely class to be inherited. 12 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz Danke für die Aufmerksamkeit! 13 © 2009, Sebastian Gäng, Moritz Moll, Design Pattern, HTWG Konstanz.
Recommended publications
  • Design Pattern Interview Questions
    DDEESSIIGGNN PPAATTTTEERRNN -- IINNTTEERRVVIIEEWW QQUUEESSTTIIOONNSS http://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm Copyright © tutorialspoint.com Dear readers, these Design Pattern Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of Design Pattern. As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer: What are Design Patterns? Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time. What is Gang of Four GOF? In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development. These authors are collectively known as Gang of Four GOF. Name types of Design Patterns? Design patterns can be classified in three categories: Creational, Structural and Behavioral patterns. Creational Patterns - These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new opreator. This gives program more flexibility in deciding which objects need to be created for a given use case. Structural Patterns - These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.
    [Show full text]
  • Design Patterns in PHP and Laravel — Kelt Dockins Design Patterns in PHP and Laravel
    Design Patterns in PHP and Laravel — Kelt Dockins Design Patterns in PHP and Laravel Kelt Dockins [email protected] Design Patterns in PHP and Laravel Kelt Dockins Dolph, Arkansas USA ISBN-13 (pbk): 978-1-4842-2450-2 ISBN-13 (electronic): 978-1-4842-2451-9 DOI 10.1007/978-1-4842-2451-9 Library of Congress Control Number: 2016961807 Copyright © 2017 by Kelt Dockins This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made.
    [Show full text]
  • Enterprise Development with Flex
    Enterprise Development with Flex Enterprise Development with Flex Yakov Fain, Victor Rasputnis, and Anatole Tartakovsky Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo Enterprise Development with Flex by Yakov Fain, Victor Rasputnis, and Anatole Tartakovsky Copyright © 2010 Yakov Fain, Victor Rasputnis, and Anatole Tartakovsky.. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: Mary E. Treseler Indexer: Ellen Troutman Development Editor: Linda Laflamme Cover Designer: Karen Montgomery Production Editor: Adam Zaremba Interior Designer: David Futato Copyeditor: Nancy Kotary Illustrator: Robert Romano Proofreader: Sada Preisch Printing History: March 2010: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Enterprise Development with Flex, the image of red-crested wood-quails, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein.
    [Show full text]
  • Learning Javascript Design Patterns
    Learning JavaScript Design Patterns Addy Osmani Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Learning JavaScript Design Patterns by Addy Osmani Copyright © 2012 Addy Osmani. All rights reserved. Revision History for the : 2012-05-01 Early release revision 1 See http://oreilly.com/catalog/errata.csp?isbn=9781449331818 for release details. ISBN: 978-1-449-33181-8 1335906805 Table of Contents Preface ..................................................................... ix 1. Introduction ........................................................... 1 2. What is a Pattern? ...................................................... 3 We already use patterns everyday 4 3. 'Pattern'-ity Testing, Proto-Patterns & The Rule Of Three ...................... 7 4. The Structure Of A Design Pattern ......................................... 9 5. Writing Design Patterns ................................................. 11 6. Anti-Patterns ......................................................... 13 7. Categories Of Design Pattern ............................................ 15 Creational Design Patterns 15 Structural Design Patterns 16 Behavioral Design Patterns 16 8. Design Pattern Categorization ........................................... 17 A brief note on classes 17 9. JavaScript Design Patterns .............................................. 21 The Creational Pattern 22 The Constructor Pattern 23 Basic Constructors 23 Constructors With Prototypes 24 The Singleton Pattern 24 The Module Pattern 27 iii Modules 27 Object Literals 27 The Module Pattern
    [Show full text]
  • Design Pattern Implementation in Java and Aspectj
    Design Pattern Implementation in Java and AspectJ Jan Hannemann Gregor Kiczales University of British Columbia University of British Columbia 201-2366 Main Mall 201-2366 Main Mall Vancouver B.C. V6T 1Z4 Vancouver B.C. V6T 1Z4 jan [at] cs.ubc.ca gregor [at] cs.ubc.ca ABSTRACT successor in the chain. The event handling mechanism crosscuts the Handlers. AspectJ implementations of the GoF design patterns show modularity improvements in 17 of 23 cases. These improvements When the GoF patterns were first identified, the sample are manifested in terms of better code locality, reusability, implementations were geared to the current state of the art in composability, and (un)pluggability. object-oriented languages. Other work [19, 22] has shown that implementation language affects pattern implementation, so it seems The degree of improvement in implementation modularity varies, natural to explore the effect of aspect-oriented programming with the greatest improvement coming when the pattern solution techniques [11] on the implementation of the GoF patterns. structure involves crosscutting of some form, including one object As an initial experiment we chose to develop and compare Java playing multiple roles, many objects playing one role, or an object [27] and AspectJ [25] implementations of the 23 GoF patterns. playing roles in multiple pattern instances. AspectJ is a seamless aspect-oriented extension to Java, which means that programming in AspectJ is effectively programming in Categories and Subject Descriptors Java plus aspects. D.2.11 [Software Engineering]: Software Architectures – By focusing on the GoF patterns, we are keeping the purpose, patterns, information hiding, and languages; D.3.3 intent, and applicability of 23 well-known patterns, and only allowing [Programming Languages]: Language Constructs and Features – the solution structure and solution implementation to change.
    [Show full text]
  • Java Design Patterns I
    Java Design Patterns i Java Design Patterns Java Design Patterns ii Contents 1 Introduction to Design Patterns 1 1.1 Introduction......................................................1 1.2 What are Design Patterns...............................................1 1.3 Why use them.....................................................2 1.4 How to select and use one...............................................2 1.5 Categorization of patterns...............................................3 1.5.1 Creational patterns..............................................3 1.5.2 Structural patterns..............................................3 1.5.3 Behavior patterns...............................................3 2 Adapter Design Pattern 5 2.1 Adapter Pattern....................................................5 2.2 An Adapter to rescue.................................................6 2.3 Solution to the problem................................................7 2.4 Class Adapter..................................................... 11 2.5 When to use Adapter Pattern............................................. 12 2.6 Download the Source Code.............................................. 12 3 Facade Design Pattern 13 3.1 Introduction...................................................... 13 3.2 What is the Facade Pattern.............................................. 13 3.3 Solution to the problem................................................ 14 3.4 Use of the Facade Pattern............................................... 16 3.5 Download the Source Code.............................................
    [Show full text]
  • Object-Oriented Design Patterns
    Object-Oriented Design Patterns David Janzen EECS 816 Object-Oriented Software Development University of Kansas Outline • Introduction – Design Patterns Overview – Strategy as an Early Example – Motivation for Creating and Using Design Patterns – History of Design Patterns • Gang of Four (GoF) Patterns – Creational Patterns – Structural Patterns – Behavioral Patterns Copyright © 2006 by David S. 2 Janzen. All rights reserved. What are Design Patterns? • In its simplest form, a pattern is a solution to a recurring problem in a given context • Patterns are not created, but discovered or identified • Some patterns will be familiar? – If you’ve been designing and programming for long, you’ve probably seen some of the patterns we will discuss – If you use Java Foundation Classes (Swing), Copyright © 2006 by David S. 3 you have certaJiannzleyn. Aulls rieghdts rsesoervmed.e design patterns Design Patterns Definition1 • Each pattern is a three-part rule, which expresses a relation between – a certain context, – a certain system of forces which occurs repeatedly in that context, and – a certain software configuration which allows these forces to resolve themselves 1. Dick Gabriel, http://hillside.net/patterns/definition.html Copyright © 2006 by David S. 4 Janzen. All rights reserved. A Good Pattern1 • Solves a problem: – Patterns capture solutions, not just abstract principles or strategies. • Is a proven concept: – Patterns capture solutions with a track record, not theories or speculation 1. James O. Coplien, http://hillside.net/patterns/definition.html Copyright © 2006 by David S. 5 Janzen. All rights reserved. A Good Pattern • The solution isn't obvious: – Many problem-solving techniques (such as software design paradigms or methods) try to derive solutions from first principles.
    [Show full text]
  • Design Patterns Mock Test
    DDEESSIIGGNN PPAATTTTEERRNNSS MMOOCCKK TTEESSTT http://www.tutorialspoint.com Copyright © tutorialspoint.com This section presents you various set of Mock Tests related to Design Patterns Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself. DDEESSIIGGNN PPAATTTTEERRNNSS MMOOCCKK TTEESSTT IIII Q 1 - Which of the following describes the Composite pattern correctly? A - This pattern builds a complex object using simple objects and using a step by step approach. B - This pattern is used where we need to treat a group of objects in similar way as a single object. C - This pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. D - This pattern is primarily used to reduce the number of objects created and to decrease memory footprint and increase performance. Q 2 - Which of the following describes the Decorator pattern correctly? A - This pattern allows a user to add new functionality to an existing object without altering its structure. B - This pattern is used where we need to treat a group of objects in similar way as a single object. C - This pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. D - This pattern is primarily used to reduce the number of objects created and to decrease memory footprint and increase performance. Q 3 - Which of the following describes the Facade pattern correctly? A - This pattern allows a user to add new functionality to an existing object without altering its structure.
    [Show full text]
  • Developing GUI Applications. Architectural Patterns Revisited
    Developing GUI Applications: Architectural Patterns Revisited A Survey on MVC, HMVC, and PAC Patterns Alexandros Karagkasidis [email protected] Abstract. Developing large and complex GUI applications is a rather difficult task. Developers have to address various common soFtware engineering problems and GUI-speciFic issues. To help the developers, a number of patterns have been proposed by the software community. At the architecture and higher design level, the Model-View-Controller (with its variants) and the Presentation-Abstraction- Control are two well-known patterns, which specify the structure oF a GUI application. However, when applying these patterns in practice, problems arise, which are mostly addressed to an insuFFicient extent in the existing literature (iF at all). So, the developers have to find their own solutions. In this paper, we revisit the Model-View-Controller, Hierarchical Model-View- Controller, and Presentation-Abstraction-Control patterns. We first set up a general context in which these patterns are applied. We then identiFy Four typical problems that usually arise when developing GUI applications and discuss how they can be addressed by each of the patterns, based on our own experience and investigation oF the available literature. We hope that this paper will help GUI developers to address the identified issues, when applying these patterns. 1 Introduction Developing a large and complex graphical user interface (GUI) application for displaying, working with, and managing complex business data and processes is a rather difficult task. A common problem is tackling system complexity. For instance, one could really get lost in large number of visual components comprising the GUI, not to mention the need to handle user input or track all the relationships between the GUI and the business logic components.
    [Show full text]
  • Design Patterns for Developing High Efficiency Mobile Application
    chnology Te & n S o o ti ft a w a m r r e Shahbudin and Chua, J Inform Tech Softw Eng 2013, 3:3 o f E Journal of n n I g f i o n DOI; 10.4172/2165-7866.1000122 l e a e n r r i n u g o J ISSN: 2165-7866 Information Technology & Software Engineering Research Article Open Access Design Patterns for Developing High Efficiency Mobile Application Fadilah Ezlina Shahbudin and Fang-Fang Chua* Faculty of Computing and Informatics, Multimedia University, Cyberjaya, Malaysia Abstract With the advent of technology, mobile devices are becoming powerful and they are widely used as convenient computing devices. In order to develop high quality application in a short period while overcoming the limitations and challenges in mobile development, strong knowledge and understanding of the design purpose are the key factors in developing well- designed applications. Good design ensures that crashes or harmful actions can be prevented as well as increasing users’ satisfaction. By implementing design patterns, developers can cater wide variety of users whereby they do not have to redevelop similar application for users who are using different types of devices. Application can be developed in a short period as developer can reuse design patterns to develop new application in similar domain. Our proposed work aims to implement design patterns to overcome limitations of current techniques and increase efficiency, usability and reusability in mobile application development. Keywords: Design patterns; Mobile application; Efficiency; Usability; many aspects and factors that need to be considered to achieve the Development specified quality attributes.
    [Show full text]
  • Gang-Of-Four Design Patterns: a Case Study of the Unified Om Del and the Eos Programming Language Hridesh Rajan Iowa State University, [email protected]
    Computer Science Technical Reports Computer Science Summer 6-30-2015 Gang-of-Four Design Patterns: A Case Study of the Unified oM del and the Eos Programming Language Hridesh Rajan Iowa State University, [email protected] Follow this and additional works at: http://lib.dr.iastate.edu/cs_techreports Part of the Programming Languages and Compilers Commons, and the Software Engineering Commons Recommended Citation Rajan, Hridesh, "Gang-of-Four Design Patterns: A Case Study of the Unified Model and the Eos Programming Language" (2015). Computer Science Technical Reports. 373. http://lib.dr.iastate.edu/cs_techreports/373 This Article is brought to you for free and open access by the Computer Science at Iowa State University Digital Repository. It has been accepted for inclusion in Computer Science Technical Reports by an authorized administrator of Iowa State University Digital Repository. For more information, please contact [email protected]. Gang-of-Four Design Patterns: A Case Study of the Unified oM del and the Eos Programming Language Abstract In earlier work, we showed that the AspectJ notions of aspect and class can be unified in a new module construct that we called the classpect, and that this new model is simpler and able to accommodate a broader set of requirements for modular solutions to complex integration problems. We embodied our unified model in the Eos language design. The ainm contribution of this article is a case study, which considers the implementation of the Gang-of-Four (GOF) design patterns in Eos to analyze the effect of new programming language constructs on these implementations. We also compare these implementations with the AspectJ's implementation.
    [Show full text]
  • Rule Object: a Pattern Language for Scalable Business Rule Design
    Rule Object 2001: A Pattern Language for Adaptive and Scalable Business Rule Construction Ali Arsanjani IBM National EAD Center of Competency, Raleigh, NC, USA Maharishi University of Management, Fairfield, Iowa, USA [email protected] Abstract Rules are changing everyday in the face of rapidly volatile business requirements. How do we handle this change while keeping our systems efficiently maintainable, reusable and extensible? How do we model and handle (represent) rules, for greater reuse, maintainability, performance? Business rules tend to change more frequently than the rest of the business object with which they are associated. These rules are typically implemented within the rule methods of a business object. Rules also refer to other business objects that their encompassing business object associates with; creating a web of implicit and increasingly unmaintainable dependencies. Thus, changing a business rule can impact the set of objects dependent upon that rule. Entropy increases even more when the code that is implementing a rule is scattered across several methods within a class, or across several methods of collaborating classes. This lack of centralization leads to ripple effects; the impact of changing a rule’s constituent if-else statements leads to side-effects. The Rule Object Pattern Language contains twenty-two patterns that cover a spectrum of solutions to common problems encountered in the realm of modeling, design and implementation (three levels) of handling business rules. For brevity only seven of these have been included in this paper.. We have however, chosen to focus our discussion around what we consider to be the more salient pattern, the Rule Object, and discuss the other patterns such as Rule Method, Simple, Composite and Compound Rule Object, Assessor, Action in light of it.
    [Show full text]