SlideShare a Scribd company logo
Mediator Pattern
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”.
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




SenderObj




                           Worker
                            Obj2
CCS Model

• SenderObject(reg,sendmedmsg,sendobjmsg,printmsg)=
  reg.sendmedmsg’.SenderObject<reg,sendmedmsg,sendobjmsg,printmsg>

• Mediator(sendmedmsg,sendobj1msg,sendobj2msg)=
  sendmedmsg.sendobj1’msg.Mediator<sendmedmsg,sendobj1msg,sendob
  j2msg> +
  sendmedmsg.sendobj2msg.Mediator<sendmedmsg,sendobj1msg,sendobj
  2msg>
• Workerobj1(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.printms
  g’.Workerobj1<reg,sendmedmsg,sendobjmsg,printmsg>
• Workerobj2(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.printms
  g’.Workerobj2<reg,sendmedmsg,sendobjmsg,printmsg>
Simulation on MWB

More Related Content

What's hot

Colegio nacional dario guevara mayorga
Colegio nacional dario guevara mayorgaColegio nacional dario guevara mayorga
Colegio nacional dario guevara mayorga
Jefferson
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced Javascript
Binu Paul
 
Krazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldrivenKrazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldriven
Krazy Koder
 
User controls
User controlsUser controls
User controls
aspnet123
 
Dagger1
Dagger1Dagger1
Dagger1
Ramesh Akula
 
Web 5 | JavaScript Events
Web 5 | JavaScript EventsWeb 5 | JavaScript Events
Web 5 | JavaScript Events
Mohammad Imam Hossain
 
MVC 2.0 - A Breakthrough
MVC 2.0 - A BreakthroughMVC 2.0 - A Breakthrough
MVC 2.0 - A Breakthrough
Constantin Dumitrescu
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
Mohammad Imam Hossain
 
Java%20 new%20faq.doc 0
Java%20 new%20faq.doc 0Java%20 new%20faq.doc 0
Java%20 new%20faq.doc 0
aravind_aashu
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
pavishkumarsingh
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
WebStackAcademy
 
Excel to Use Rest API to communicate with a server
Excel to Use Rest API to communicate with a serverExcel to Use Rest API to communicate with a server
Excel to Use Rest API to communicate with a server
docuboy
 
Dynamic databinding
Dynamic databindingDynamic databinding
Dynamic databinding
Gagan Vishal Mishra
 
Validation using javascripts by karan chanana
Validation using javascripts by karan chananaValidation using javascripts by karan chanana
Validation using javascripts by karan chanana
karan info
 
Add two numbers karan chanana
Add two numbers karan chananaAdd two numbers karan chanana
Add two numbers karan chanana
karan info
 
Inventory management
Inventory managementInventory management
Inventory management
Rajeev Sharan
 

What's hot (16)

Colegio nacional dario guevara mayorga
Colegio nacional dario guevara mayorgaColegio nacional dario guevara mayorga
Colegio nacional dario guevara mayorga
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced Javascript
 
Krazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldrivenKrazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldriven
 
User controls
User controlsUser controls
User controls
 
Dagger1
Dagger1Dagger1
Dagger1
 
Web 5 | JavaScript Events
Web 5 | JavaScript EventsWeb 5 | JavaScript Events
Web 5 | JavaScript Events
 
MVC 2.0 - A Breakthrough
MVC 2.0 - A BreakthroughMVC 2.0 - A Breakthrough
MVC 2.0 - A Breakthrough
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
 
Java%20 new%20faq.doc 0
Java%20 new%20faq.doc 0Java%20 new%20faq.doc 0
Java%20 new%20faq.doc 0
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Excel to Use Rest API to communicate with a server
Excel to Use Rest API to communicate with a serverExcel to Use Rest API to communicate with a server
Excel to Use Rest API to communicate with a server
 
Dynamic databinding
Dynamic databindingDynamic databinding
Dynamic databinding
 
Validation using javascripts by karan chanana
Validation using javascripts by karan chananaValidation using javascripts by karan chanana
Validation using javascripts by karan chanana
 
Add two numbers karan chanana
Add two numbers karan chananaAdd two numbers karan chanana
Add two numbers karan chanana
 
Inventory management
Inventory managementInventory management
Inventory management
 

Viewers also liked

Mediator pattern
Mediator patternMediator pattern
Mediator pattern
Md. Mahedi Mahfuj
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
Julie Iskander
 
Mediator Pattern
Mediator PatternMediator Pattern
Mediator Pattern
Anuj Pawar
 
Proxy design pattern
Proxy design patternProxy design pattern
Proxy design pattern
Sase Kleckovski
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
Shakil Ahmed
 
Mediator
MediatorMediator
Mediator
Iryney Baran
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 

Viewers also liked (7)

Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
 
Mediator Pattern
Mediator PatternMediator Pattern
Mediator Pattern
 
Proxy design pattern
Proxy design patternProxy design pattern
Proxy design pattern
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Mediator
MediatorMediator
Mediator
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

Similar to mediator

mediator
mediatormediator
mediator
Vivek Mahajan
 
Javascript
JavascriptJavascript
Javascript
Gita Kriz
 
25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt
PiyushAery
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
Tareq Hasan
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
Phúc Đỗ
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
Stefano Fago
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OO
John Hunter
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Building .NET-based Applications with C#
Building .NET-based Applications with C#Building .NET-based Applications with C#
Building .NET-based Applications with C#
Umar Farooq
 
Week 9 IUB c#
Week 9 IUB c#Week 9 IUB c#
Week 9 IUB c#
Umar Farooq
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
Jalpesh Vasa
 
Metaprogramming in JavaScript
Metaprogramming in JavaScriptMetaprogramming in JavaScript
Metaprogramming in JavaScript
Mehdi Valikhani
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
Mukesh Tekwani
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
Mukesh Tekwani
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
uEngine Solutions
 
Java script objects 1
Java script objects 1Java script objects 1
Java script objects 1
H K
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An Introduction
Knoldus Inc.
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
Anand Dhana
 
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
Mario Fusco
 
Linked In Presentation
Linked In PresentationLinked In Presentation
Linked In Presentation
apweir12
 

Similar to mediator (20)

mediator
mediatormediator
mediator
 
Javascript
JavascriptJavascript
Javascript
 
25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt25-inheritance-polymorphism.ppt
25-inheritance-polymorphism.ppt
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OO
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Building .NET-based Applications with C#
Building .NET-based Applications with C#Building .NET-based Applications with C#
Building .NET-based Applications with C#
 
Week 9 IUB c#
Week 9 IUB c#Week 9 IUB c#
Week 9 IUB c#
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Metaprogramming in JavaScript
Metaprogramming in JavaScriptMetaprogramming in JavaScript
Metaprogramming in JavaScript
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 
Java script objects 1
Java script objects 1Java script objects 1
Java script objects 1
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An Introduction
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
 
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
 
Linked In Presentation
Linked In PresentationLinked In Presentation
Linked In Presentation
 

Recently uploaded

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 

Recently uploaded (20)

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 

mediator

  • 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”.
  • 5.
  • 6.
  • 7. 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.
  • 8. • Balance the principle of decoupling with the principle of distributing responsibility evenly. • Be careful not to create a “controller” or “god” object.
  • 9. 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
  • 10. 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); } }
  • 11. 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); }
  • 12. 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
  • 13. 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); } } }
  • 14. 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);
  • 15. Flow diagram WorkerObj1 SenderObj Worker Obj2
  • 16. CCS Model • SenderObject(reg,sendmedmsg,sendobjmsg,printmsg)= reg.sendmedmsg’.SenderObject<reg,sendmedmsg,sendobjmsg,printmsg> • Mediator(sendmedmsg,sendobj1msg,sendobj2msg)= sendmedmsg.sendobj1’msg.Mediator<sendmedmsg,sendobj1msg,sendob j2msg> + sendmedmsg.sendobj2msg.Mediator<sendmedmsg,sendobj1msg,sendobj 2msg> • Workerobj1(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.printms g’.Workerobj1<reg,sendmedmsg,sendobjmsg,printmsg> • Workerobj2(reg,sendmedmsg,sendobjmsg,printmsg)=sendobjmsg.printms g’.Workerobj2<reg,sendmedmsg,sendobjmsg,printmsg>