`
shake863
  • 浏览: 661412 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Design Patterns in ActionScript-Mediator

阅读更多

Ok, the last pattern now. Let’s take a look the intent directly.

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.

– By THE GOF BOOK

From this intent, we can get that this pattern is use for encapsulating the interaction of objects.

 

 

For example, when you build a GUI application, you may enable or disable the button when the user input something, you may add a listener for the text change event. Then, when the event happens, you change the state of that button. It means that you must know the button object, and some details about the button. As you application going further, you may do many things in that function, also, you need to know many classes’ detail. When the requirement changed, you need to fix many things. And your classes maybe look like as follows.

clip_image001

With the help of Mediator pattern, you reduce the complexity of each widget, they don’t even need to know the existence of other widgets, and they only need to know the mediator. When an object changes, it tells the mediator, then the mediator notify the other objects. In this pattern, you put the complexity from the widget to the mediator. The mediator needs to know everything. And the classes changes to below.

clip_image002

In GoF, all the widgets will inherit a super class Colleague, and the widgets is called concrete colleague. When the widget’s state changes, it calls the widgetChanged() method. My simple implementation of colleague is as follows.

  1. public class Colleague
  2. {
  3. private   var mediator : Mediator ;
  4.  
  5. public   function Colleague ( mediator : Mediator )
  6. {
  7. this . mediator = mediator ;
  8. }
  9.  
  10. public   function hasChanged () : String
  11. {
  12. return   mediator . detectChanged ( this ) ;
  13. }
  14. }

In the concrete mediator, we need to distinguish which objects call the method, and here is my implementation.

  1. public function detectChanged ( colleague : Colleague ) : String
  2. {
  3. if ( colleague == colleague1 )
  4. return   colleague2 . operation2 () ;
  5. else   if ( colleague == colleague2 )
  6. return   colleague1 . operation1 () ;
  7.  
  8. return   null ;
  9. }

And the class diagram below is from the GoF.

clip_image003

Hope this helps. That’s all for this pattern.Download Download Full Project

Thanks for you kindness in reading those articles, especially for those who make comments. Actually, I’m a fresh man in design patterns; the main reason that I wrote those articles is to help me learn more quickly. If there is any wrong that troubles you, I’ve to say sorry here, sincerely! If you have any questions, contact me, liubo.cs@hotmail.com .

分享到:
评论

相关推荐

    Go Design Patterns for Real-World Projects epub

    Go Design Patterns for Real-World Projects 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Go Design Patterns for Real-World Projects azw3

    Go Design Patterns for Real-World Projects 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Data Structures and Algorithms with Object-Oriented Design Patterns in CSharp - Bruno R. Preiss.chm

    Data Structures and Algorithms with Object-Oriented Design Patterns in CSharp - Bruno R. Preiss

    Laracasts - design-patterns-in-php

    "Laracasts - design-patterns-in-php.torrent"则可能是一个BT种子文件,用于通过BitTorrent协议下载整个课程的大型数据包,这通常包括所有视频讲座和其他相关文件。 在课程"设计模式在PHP中"中,你可能会学到以下...

    Design-Patterns-in-Modern-C++

    The topic of Design Patterns sounds dry, academically constipated and, in all honesty, done to death in almost every programming language imaginable—including programming languages such as JavaScript...

    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-for-humans设计模式中文翻译版

    https://github.com/kamranahmedse/design-patterns-for-humans 中文翻译,实例修改位JAVA代码

    Design-Patterns-In-Kotlin,在kotlin中实现的设计模式.zip

    《Kotlin设计模式实战解析》 在编程领域,设计模式是一种通用、可重用的...开源项目"Design-Patterns-In-Kotlin"则是一个很好的学习资源,它提供了各种设计模式在Kotlin中的具体实现,有助于开发者深入学习和实践。

    Go Design Patterns for Real-World Projects.epub

    Go: Design Patterns for Real-World Projects What You Will Learn: Install and configure the Go development environment to quickly get started with your first program Use the basic elements of the ...

    Java+Enterprise+Design+Patterns+-+Patterns+in+Java+Volume+3

    Java+Enterprise+Design+Patterns+-+Patterns+in+Java+Volume+3Java+Enterprise+Design+Patterns+-+Patterns+in+Java+Volume+3

    Design Patterns in ActionScript

    《ActionScript设计模式》是软件开发领域中针对ActionScript编程语言的一种实践指南,它深入探讨了如何在ActionScript项目中应用经典的设计模式。设计模式是软件工程中的宝贵经验总结,它们是解决常见问题的可复用...

    Pro-Objective-C-Design-Patterns-for-iOS

    《Pro-Objective-C-Design-Patterns-for-iOS》是一本专注于在iOS平台上利用Objective-C语言实现设计模式的专业书籍。书中旨在帮助已经有一定Cocoa开发基础的开发者,通过掌握设计模式的实践应用,提升软件开发的生产...

    2010-13-Design Patterns for Safety-Critical.pdf

    在本论文“2010-13-Design Patterns for Safety-Critical”中,作者Ashraf Armoush探讨了如何将设计模式的概念应用于安全关键嵌入式系统的开发。他构建了一个设计模式目录,这个目录包含了一系列针对硬件和软件的...

    design-patterns-c-sharp

    "design-patterns-c-sharp"这个主题涵盖了C#编程环境中如何应用这些模式的知识。 首先,我们需要理解设计模式的基本概念。设计模式并不具体到任何特定的代码或库,而是一种描述在特定情况下如何设计软件组件的通用...

Global site tag (gtag.js) - Google Analytics