`
dr2tr
  • 浏览: 138720 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Design Patterns -- Mediator

阅读更多

1. The Medaitor pattern centralizes responsibility for a particular set of objects. (Singleton pattern is for the clients.) The Mediator pattern defines an object that encapsulates how a set of object interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.  see pic:

 

2.  Mediator shows up most often in GUI application development. Java Swing components apply the Mediator pattern, notifying a mediator when events occur rather than taking reaponsibility for updating other components directly.

3 . For maintaining the ralational integrity in an object model, Mediator is also usefule. When we have an object model that is not tied to a relational database( maybe not suitable), we can use mediators to sustain the relational integrity of our model. Move the  gets and sets relations between objects into mediator.

4. We can apply mediator whenever we need to define an object that encapsulates how a set of objects interact.

5. Here giving an example for implements:

5.1 public interface Mediator { }

5.2 Concrete Mediator :

public class ConcreteMediator implements Mediator {

   //suppose there are 2 colleagues at present
   private ConcreteColleague1 colleague1 = new ConcreteColleague1();
   private ConcreteColleague2 colleague2 = new ConcreteColleague2();

   ...  // here we usually do some interact work( maybe deal with some relations....

}

5.3 Colleague :

public class Colleague {
   private Mediator mediator;
   public Mediator getMediator() {
      return mediator;
   }

   public void setMediator( Mediator mediator ) {
      this.mediator = mediator;
   }
}

public class ConcreteColleague1 { }

public class ConcreteColleague2 { }

 

 

 

 
分享到:
评论

相关推荐

    Packt.Go.Design.Patterns.2017

    Behavioral Patterns - Visitor, State, Mediator, and Observer Design Patterns Chapter 8. Introduction to Gos Concurrency Chapter 9. Concurrency Patterns - Barrier, Future, and Pipeline Design Patterns...

    Design Patterns in Modern C++--2018

    Reusable Approaches for Object-Oriented... Work with the behavioral patterns such as chain of responsibility, command, iterator, mediator and more Apply functional design patterns such as Monad and more

    Design.Patterns.Explained.Simply

    We've tried hard to avoid both of these categories with Design Patterns Explained Simply. This book is fast and simple way to get the idea behind each of the 29 popular design patterns. The book is ...

    Beginning SOLID Principles and Design Patterns for ASP.NET Developers.pdf

    ■Chapter 8: Behavioral Patterns: Mediator, Memento, and Observer ■Chapter 9: Behavioral Patterns: State, Strategy, Template Method, and Visitor ■Chapter 10: Patterns of Enterprise Application ...

    Design Patterns Elements of Reusable Object-Oriented Software

    • How Design Patterns Solve Design Problems • How to Select a Design Pattern • How to Use a Design Pattern A Case Study: Designing a Document Editor • Design Problems • Document Structure ...

    Apress.Pro.Design.Patterns.in.Swift

    Pro Design Patterns in Swift shows you how to harness the power and flexibility of Swift to apply the most important and enduring design patterns to your applications, taking your development ...

    《Java Design Patterns》高清完整英文PDF版

    Chapter 18: Mediator Patterns Chapter 19: Prototype Patterns Chapter 20: Chain of Responsibility Patterns Chapter 21: Composite Patterns Chapter 22: Bridge Patterns (Or Handle/Body Patterns) Chapter ...

    designpatterns-java:Java设计模式

    设计模式 调解人模式 它用于封装相关对象(称为同事)之间的... package mediator ; public class StockMarketApp { public static void main ( String [] args ) { StockMediator nyse = new StockMediator ();

    design patterns elements of reusable object-oriented software

    ★附录A介绍了剩下的设计模式:Bridge(桥接)、Builder(生成器)、Chainof Responsibility(责任链)、Flyweight(蝇量)、Interpreter(解释器)、Mediator(中介者)、Memento(备忘录)、Prototype(原型)、...

    Head First Design Patterns 高清英文版

    至于第14章则很快地浏览尚未介绍的设计模式,包括Bridge、Builder、Chain of Responsibility、Flyweight、Interpreter、Mediator、Memento、Prototype,Visitor。第1章还介绍了四个○○基本概念(抽象、封装、继承、...

    Head First Design Patterns 英文版 Head First设计模式

    《Head First Design Patterns》编辑推荐:强大的写作阵容。《Head First Design Patterns》作者Eric Freeman;ElElisabeth Freeman是作家、讲师和技术顾问。Eric拥有耶鲁大学的计算机科学博士学位,E1isabath拥有...

    Head First Design Patterns

    Flyweight、Interpreter、Mediator、Memento、Prototype、Visitor。第1章还介绍了四个OO基本概念(抽象、封装、继承、多态),而第1章到第9章也陆续介绍了九个OO原则(Principle)。 千万不要轻视这些OO原则,因为...

    100-words-design-patterns-java:GoF设计模式,每个模式都描述了真实生活中的故事

    官方网站: Java中的100个单词GoF设计模式 介绍 想法:以一种简单的方式描述GoF设计模式。每个模式将通过以下结构进行描述: 故事(少于100个字) 用Java实现 GoF设计模式 创作模式 结构模式 ...

    Java.Design.Patterns.1537192353

    Java design patterns with the Simplest real world examples which are easy to understand & remember as well. Table of Contents PREFACE ABOUT DESIGN PATTERNS SINGLETON PATTERN FACTORY PATTERN ABSTRACT ...

    精通Objective-C设计模式 源代码

    You’ll also discover less well-known but useful patterns like memento, composite, command, and mediator. What you’ll learn The basic concepts of various design patterns How to apply design ...

    typescript-design-patterns:TypeScript中的设计模式

    TypeScript Design Patterns 该项目基于 TypeScript 实现了下列设计模式: Creational(创建型模式) Structural Patterns(结构型模式) Bridge Composite Behavioral Patterns(行为型模式) Command Interpreter ...

    head first design patterns 英文原版高清

    至于第14章则很快地浏览尚未介绍的设计模式,包括Bridge、Builder、ChainofResponsibility、Flyweight、Interpreter、Mediator、Memento、Prototype,Visitor。第1章还介绍了四个基本概念(抽象、封装、继承、多态),...

    designPatterns:设计模式

    design pattern 设计模式 创建型设计模式 创建型模式设计到将对象实例化,这类模式都提供了一个方法,将客户从所需要的实例化对象中解耦。 原型模式 Prototype 结构型设计模式 结构型模式可以让你把类或者对象组合到...

    用于人类的csharp-design-patterns:“人类的设计模式”-超简化的解释-C#示例

    适应C#的 对设计模式的所有解释均保持不变,只是有微小的变化。 :party_popper: 超简化的设计模式说明! :party_popper: 一个很容易使任何人的思想摇摆不定的话题。 在这里,我尝试通过尽可能简单的方式来解释...

    C++设计模式(Design Pattern)范例源代码

    23种设计模式(Design Pattern)的C++实现范例,包括下面列出的各种模式,代码包含较详细注释。另外附上“设计模式迷你手册.chm”供参考。 注:项目在 VS2008 下使用。 创建型: 抽象工厂模式(Abstract Factory) 生成...

Global site tag (gtag.js) - Google Analytics