SlideShare a Scribd company logo
1 of 18
Motivations

 lots of classes in the design of framework
 If certain principles are not applied the final
  framework will end in a total mess
 to avoid tight coupled frameworks, we need a
  mechanism to facilitate the interaction between
  objects in a manner in that objects are not aware of the
  existence of other objects.
Mediator


  Mediator promotes loose coupling by keeping objects
 from referring to each other explicitly
Intent

 Define an object that encapsulates how a set of objects
  interact.
 Design an intermediary to decouple many peers
 Promote the many-to-many relationships between
  interacting peers to “full object status”.
Unmediated
Mediated
Mediator
Check list

 Identify a collection of interacting objects that would
  benefit from mutual decoupling.
 Encapsulate those interactions in the abstraction of a
  new class.
 Create an instance of that new class and rework all
  “peer” objects to interact with the Mediator only.
 Balance the principle of decoupling with the principle
  of distributing responsibility evenly.
 Be careful not to create a “controller” or “god” object.
Mediator design example


 Let us consider design of a class in which one object
 send messages to other objects by means of if then if
 condition explicitly
public class WorkerObject
   {
      private string _message;

        public WorkerObject(string message)
        {
          _message = message;
        }

        public string Message
        {
          get{return _message;}
          set{_message = value;}
        }

        public SendMessage(string message)
        {
          Console.WriteLine(quot;Message sent : quot; + message);
        }
    }
WorkerObject senderObject = new WorkerObject(quot;message0quot;);
WorkerObject workerObject1 = new WorkerObject(quot;message1quot;);
WorkerObject workerObject2 = new WorkerObject(quot;message2quot;);
WorkerObject workerObject3 = new WorkerObject(quot;message3quot;);
if(!workerObject1.Message.Equals(senderObject.Message))
{
   workerObject1.SendMessage(senderObject.Message);
}
if(!workerObject2.Message.Equals(senderObject.Message))
{
   workerObject2.SendMessage(senderObject.Message);
}
if(!workerObject3.Message.Equals(senderObject.Message))
{
   workerObject3.SendMessage(senderObject.Message);
}
Mediator
 we create a mediator class, DoSomeMediation.
 This class contains two methods Register and
  SendMessage
 The Register method catalogs all the classes we want
  to mediate between.
 The SendMessage method is where the functional
  code actually exists
public class DoSomeMediation
   {
         private static ArrayList _workerObjects = new ArrayList();

            public static int Register(WorkerObject workerObject)
        {
                    return _workerObjects.Add(workerObject);
            }
            public static void SendMessage(WorkerObject senderObject)
            {
              if(senderObject == null) return;
              string messageToSend = senderObject.Message;

                    foreach(WorkerObject workerObject in _workerObjects)
                    {
                        //send message to all other objects registered
                                   if(!workerObject.Message.Equals(senderObject.Message))
                                        workerObject.SendMessage(messageToSend);
                }
            }
    }
WorkerObject senderObject = new WorkerObject(quot;message0quot;);
WorkerObject workerObject1 = new WorkerObject(quot;message1quot;);
WorkerObject workerObject2 = new WorkerObject(quot;message2quot;);
WorkerObject workerObject3 = new WorkerObject(quot;message3quot;);
DoSomeMediation.Register(senderObject);
DoSomeMediation.Register(workerObject1);
DoSomeMediation.Register(workerObject2);
DoSomeMediation.Register(workerObject3);
DoSomeMediation.SendMessage(senderObject);
Flow diagram
                        WorkerObj1




             Mediator
 SenderObj




                           Worker
                            Obj2
CCS Model

 SenderObject(reg,sendmedmsg,sendobjmsg,printmsg)=
  reg.sendmedmsg’.SenderObject<reg,sendmedmsg,sendobjmsg,printms
  g>

 Mediator(sendmedmsg,sendobj1msg,sendobj2msg)=
  sendmedmsg.sendobj1msg’.Mediator<sendmedmsg,sendobj1msg,sendo
  bj2msg> +
  sendmedmsg.sendobj2msg’.Mediator<sendmedmsg,sendobj1msg,send
  obj2msg>
 Workerobj1(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.prin
  tmsg’.Workerobj1<reg,sendmedmsg,sendobjmsg,printmsg>
 Workerobj2(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.prin
  tmsg’.Workerobj2<reg,sendmedmsg,sendobjmsg,printmsg>
Simulation on MWB

More Related Content

What's hot (17)

Vs c# lecture11
Vs c# lecture11Vs c# lecture11
Vs c# lecture11
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
 
React tips
React tipsReact tips
React tips
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Presentation cs313 (1)
Presentation cs313 (1)Presentation cs313 (1)
Presentation cs313 (1)
 
Lesson3
Lesson3Lesson3
Lesson3
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
React lecture
React lectureReact lecture
React lecture
 
AutoComplete
AutoCompleteAutoComplete
AutoComplete
 
16 18
16 1816 18
16 18
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
Deceptive simplicity of async and await
Deceptive simplicity of async and awaitDeceptive simplicity of async and await
Deceptive simplicity of async and await
 
Dependency Injection for Android
Dependency Injection for AndroidDependency Injection for Android
Dependency Injection for Android
 
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
 
React hooks beyond hype
React hooks beyond hypeReact hooks beyond hype
React hooks beyond hype
 
Ajax Part II
Ajax Part IIAjax Part II
Ajax Part II
 

Viewers also liked

Tally Sheet Results - Technology Habits
Tally Sheet Results - Technology HabitsTally Sheet Results - Technology Habits
Tally Sheet Results - Technology Habitsleouy
 
Estandares aprendizaje mcs
Estandares aprendizaje mcsEstandares aprendizaje mcs
Estandares aprendizaje mcsGeovanny Armijos
 
Retrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s YearRetrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s Yearsdelastic
 
Java Eye Architecture
Java Eye ArchitectureJava Eye Architecture
Java Eye ArchitectureRobbin Fan
 
The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...Mohammed Farrag
 
Practical Econ, U1, Packet 1
Practical Econ, U1, Packet 1Practical Econ, U1, Packet 1
Practical Econ, U1, Packet 1NHSDAnderson
 
Mortel Scooter Campaign
Mortel Scooter CampaignMortel Scooter Campaign
Mortel Scooter Campaignsdelastic
 
Ruby In Enterprise Development
Ruby In Enterprise DevelopmentRuby In Enterprise Development
Ruby In Enterprise DevelopmentRobbin Fan
 
Cymphonix Launches iPhone App and New Version of Network Composer Software
Cymphonix Launches iPhone App and New Version of Network Composer SoftwareCymphonix Launches iPhone App and New Version of Network Composer Software
Cymphonix Launches iPhone App and New Version of Network Composer SoftwareJulie Tangen
 
Wiki Technology By It Rocks
Wiki Technology By It RocksWiki Technology By It Rocks
Wiki Technology By It Rocksnaveenv
 
что нас объединяет
что нас объединяетчто нас объединяет
что нас объединяетArtem Iljin
 
第12週-2
第12週-2第12週-2
第12週-2fudy9015
 

Viewers also liked (20)

Europe
EuropeEurope
Europe
 
Tally Sheet Results - Technology Habits
Tally Sheet Results - Technology HabitsTally Sheet Results - Technology Habits
Tally Sheet Results - Technology Habits
 
Estandares aprendizaje mcs
Estandares aprendizaje mcsEstandares aprendizaje mcs
Estandares aprendizaje mcs
 
Retrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s YearRetrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s Year
 
Java Eye Architecture
Java Eye ArchitectureJava Eye Architecture
Java Eye Architecture
 
The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...The practices, challenges and opportunities of board composition and leadersh...
The practices, challenges and opportunities of board composition and leadersh...
 
Collaborative Assessment
Collaborative AssessmentCollaborative Assessment
Collaborative Assessment
 
Practical Econ, U1, Packet 1
Practical Econ, U1, Packet 1Practical Econ, U1, Packet 1
Practical Econ, U1, Packet 1
 
Debt Taxes
Debt TaxesDebt Taxes
Debt Taxes
 
Unit3
Unit3Unit3
Unit3
 
Èdip per a 4rt de la ESO
Èdip per a 4rt de la ESOÈdip per a 4rt de la ESO
Èdip per a 4rt de la ESO
 
Mortel Scooter Campaign
Mortel Scooter CampaignMortel Scooter Campaign
Mortel Scooter Campaign
 
geek_lifestyle
geek_lifestylegeek_lifestyle
geek_lifestyle
 
Ruby In Enterprise Development
Ruby In Enterprise DevelopmentRuby In Enterprise Development
Ruby In Enterprise Development
 
Cymphonix Launches iPhone App and New Version of Network Composer Software
Cymphonix Launches iPhone App and New Version of Network Composer SoftwareCymphonix Launches iPhone App and New Version of Network Composer Software
Cymphonix Launches iPhone App and New Version of Network Composer Software
 
0 to enterprise
0 to enterprise0 to enterprise
0 to enterprise
 
Wiki Technology By It Rocks
Wiki Technology By It RocksWiki Technology By It Rocks
Wiki Technology By It Rocks
 
Vision
VisionVision
Vision
 
что нас объединяет
что нас объединяетчто нас объединяет
что нас объединяет
 
第12週-2
第12週-2第12週-2
第12週-2
 

Similar to mediator

Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptSaadAsim11
 
Improving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfImproving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfIain Hull
 
25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.pptPiyushAery
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Beneluxyohanbeschi
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oopLearningTech
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptJulie Iskander
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive ShellGiovanni Lodi
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq Hasan
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OOJohn Hunter
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascriptrelay12
 
properties-how-do-i - Transcript.pdf
properties-how-do-i - Transcript.pdfproperties-how-do-i - Transcript.pdf
properties-how-do-i - Transcript.pdfShaiAlmog1
 

Similar to mediator (20)

mediator2
mediator2mediator2
mediator2
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
 
Improving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfImproving Correctness with Types Kats Conf
Improving Correctness with Types Kats Conf
 
25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive Shell
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OO
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Javascript
JavascriptJavascript
Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Java script
Java scriptJava script
Java script
 
properties-how-do-i - Transcript.pdf
properties-how-do-i - Transcript.pdfproperties-how-do-i - Transcript.pdf
properties-how-do-i - Transcript.pdf
 

Recently uploaded

Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.GabrielaMiletti
 
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...Angela Justice, PhD
 
Mysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime Mysore
Mysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime MysoreMysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime Mysore
Mysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime Mysoremeghakumariji156
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfKen Fuller
 
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...gajnagarg
 
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...gynedubai
 
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
Miletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfMiletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfGabrielaMiletti
 
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制yynod
 
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfB.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfDeepak15CivilEngg
 
Kannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best Service
Kannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best ServiceKannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best Service
Kannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证eqaqen
 
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证eqaqen
 
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一
如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一
如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一ozave
 
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime MalegaonVip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaonmeghakumariji156
 
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...gajnagarg
 
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...gajnagarg
 
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 

Recently uploaded (20)

Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
 
Mysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime Mysore
Mysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime MysoreMysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime Mysore
Mysore Escorts Service Girl ^ 9332606886, WhatsApp Anytime Mysore
 
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdfreStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
reStartEvents 5:9 DC metro & Beyond V-Career Fair Employer Directory.pdf
 
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
 
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
 
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
 
Miletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdfMiletti Gabriela_Vision Plan for artist Jahzel.pdf
Miletti Gabriela_Vision Plan for artist Jahzel.pdf
 
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
 
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfB.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
 
Kannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best Service
Kannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best ServiceKannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best Service
Kannada Call Girls Mira Bhayandar WhatsApp +91-9930687706, Best Service
 
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
 
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
 
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
 
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Jabalpur [ 7014168258 ] Call Me For Genuine Models ...
 
如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一
如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一
如何办理堪培拉大学毕业证(UC毕业证书)成绩单原版一比一
 
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime MalegaonVip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
 
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
 
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
 
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Shillong [ 7014168258 ] Call Me For Genuine Models ...
 

mediator

  • 1.
  • 2. Motivations  lots of classes in the design of framework  If certain principles are not applied the final framework will end in a total mess  to avoid tight coupled frameworks, we need a mechanism to facilitate the interaction between objects in a manner in that objects are not aware of the existence of other objects.
  • 3. Mediator Mediator promotes loose coupling by keeping objects from referring to each other explicitly
  • 4. Intent  Define an object that encapsulates how a set of objects interact.  Design an intermediary to decouple many peers  Promote the many-to-many relationships between interacting peers to “full object status”.
  • 8. Check list  Identify a collection of interacting objects that would benefit from mutual decoupling.  Encapsulate those interactions in the abstraction of a new class.  Create an instance of that new class and rework all “peer” objects to interact with the Mediator only.
  • 9.  Balance the principle of decoupling with the principle of distributing responsibility evenly.  Be careful not to create a “controller” or “god” object.
  • 10. Mediator design example  Let us consider design of a class in which one object send messages to other objects by means of if then if condition explicitly
  • 11. public class WorkerObject { private string _message; public WorkerObject(string message) { _message = message; } public string Message { get{return _message;} set{_message = value;} } public SendMessage(string message) { Console.WriteLine(quot;Message sent : quot; + message); } }
  • 12. WorkerObject senderObject = new WorkerObject(quot;message0quot;); WorkerObject workerObject1 = new WorkerObject(quot;message1quot;); WorkerObject workerObject2 = new WorkerObject(quot;message2quot;); WorkerObject workerObject3 = new WorkerObject(quot;message3quot;); if(!workerObject1.Message.Equals(senderObject.Message)) { workerObject1.SendMessage(senderObject.Message); } if(!workerObject2.Message.Equals(senderObject.Message)) { workerObject2.SendMessage(senderObject.Message); } if(!workerObject3.Message.Equals(senderObject.Message)) { workerObject3.SendMessage(senderObject.Message); }
  • 13. Mediator  we create a mediator class, DoSomeMediation.  This class contains two methods Register and SendMessage  The Register method catalogs all the classes we want to mediate between.  The SendMessage method is where the functional code actually exists
  • 14. public class DoSomeMediation { private static ArrayList _workerObjects = new ArrayList(); public static int Register(WorkerObject workerObject) { return _workerObjects.Add(workerObject); } public static void SendMessage(WorkerObject senderObject) { if(senderObject == null) return; string messageToSend = senderObject.Message; foreach(WorkerObject workerObject in _workerObjects) { //send message to all other objects registered if(!workerObject.Message.Equals(senderObject.Message)) workerObject.SendMessage(messageToSend); } } }
  • 15. WorkerObject senderObject = new WorkerObject(quot;message0quot;); WorkerObject workerObject1 = new WorkerObject(quot;message1quot;); WorkerObject workerObject2 = new WorkerObject(quot;message2quot;); WorkerObject workerObject3 = new WorkerObject(quot;message3quot;); DoSomeMediation.Register(senderObject); DoSomeMediation.Register(workerObject1); DoSomeMediation.Register(workerObject2); DoSomeMediation.Register(workerObject3); DoSomeMediation.SendMessage(senderObject);
  • 16. Flow diagram WorkerObj1 Mediator SenderObj Worker Obj2
  • 17. CCS Model  SenderObject(reg,sendmedmsg,sendobjmsg,printmsg)= reg.sendmedmsg’.SenderObject<reg,sendmedmsg,sendobjmsg,printms g>  Mediator(sendmedmsg,sendobj1msg,sendobj2msg)= sendmedmsg.sendobj1msg’.Mediator<sendmedmsg,sendobj1msg,sendo bj2msg> + sendmedmsg.sendobj2msg’.Mediator<sendmedmsg,sendobj1msg,send obj2msg>  Workerobj1(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.prin tmsg’.Workerobj1<reg,sendmedmsg,sendobjmsg,printmsg>  Workerobj2(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.prin tmsg’.Workerobj2<reg,sendmedmsg,sendobjmsg,printmsg>