{"id":121141,"date":"2024-09-16T04:55:15","date_gmt":"2024-09-16T02:55:15","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=121141"},"modified":"2024-09-16T04:55:15","modified_gmt":"2024-09-16T02:55:15","slug":"csharp-mediator-design-pattern","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/","title":{"rendered":"Mediator Design Pattern in C#"},"content":{"rendered":"<p>\u00a0In this article, we are going to talk about a popular design pattern, the Mediator Pattern. We will see how this pattern helps address some design problems and how to implement it in C#.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-design-patterns\/MediatorPattern\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let\u2019s start.<\/p>\n<h2>What is The Mediator Design Pattern?<\/h2>\n<p>Mediator is a behavioral design pattern that promotes loose coupling by eliminating chaotic inter-dependencies.<\/p>\n<p>This pattern emphasizes the use of a mediator instead of direct interaction between components:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorDesignPattern-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123358\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorDesignPattern-2.png\" alt=\"Structure of Mediator Pattern\" width=\"561\" height=\"461\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorDesignPattern-2.png 561w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorDesignPattern-2-300x247.png 300w\" sizes=\"auto, (max-width: 561px) 100vw, 561px\" \/><\/a><\/p>\n<p>The <strong>Mediator<\/strong> sits at the center of this structure which can be orchestrated as a pair of <code>IMediator<\/code> interface and its concrete implementation. <strong>A mediator receives notifications from one component and decides which other component can carry out further operations and interact accordingly<\/strong>.<\/p>\n<p><strong>Components<\/strong> (aka colleagues) are unaware of other components, reflecting the key purpose of this pattern.\u00a0<span style=\"margin: 0px; padding: 0px;\">A component may notify the\u00a0<strong>Mediator<\/strong> with relevant event\/state data during a certain operation<\/span>. The event carries the necessary information to help the mediator choose the next component to interact with. A component may also receive a reaction from the mediator as an aftereffect of another component&#8217;s operation.\u00a0<\/p>\n<p>Before a mediator can act as a liaison, it needs a way to establish connections with the participating components:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorAndComponents-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123359\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorAndComponents-2.png\" alt=\"Mediator and Components\" width=\"401\" height=\"121\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorAndComponents-2.png 401w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/MediatorAndComponents-2-300x91.png 300w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/a><\/p>\n<p>One way to do this is to declare a property for each component and assign it explicitly from the client code (Figure 1). This is the case when components do not share a base class\/interface. However, a more favorable approach is to provide a method to register components by their shared contract (Figure 2).<\/p>\n<h3>Intercommunication Between Components<\/h3>\n<p>The true intent of a mediator is to coordinate intercommunication between components.\u00a0Hence a classic mediator facilitates bi-directional interaction:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Coordinator.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123361\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Coordinator.png\" alt=\"Execution Flow in Coordinator Mediator Pattern\" width=\"656\" height=\"161\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Coordinator.png 656w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Coordinator-300x74.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><\/p>\n<p>As we see, the execution flow starts from the component end, like when the client code invokes <code>operationA()<\/code> on <code>ComponentA<\/code>, for example. During the execution of <code>operationA()<\/code>, the <code>Mediator<\/code> receives feedback and executes <code>reactionB()<\/code> on <code>ComponentB<\/code>. A similar execution flow happens when the client invokes the operation on <code>ComponentB<\/code>.<\/p>\n<p>So, in a bi-directional flow, components are subjected to a level of coupling to the mediator.<\/p>\n<p>Sometimes it&#8217;s more favorable when components are completely unaware of the mediator. This is possible when we design the mediator as a controller rather than a coordinator.<\/p>\n<p>Such cases involve one-way communication between the mediator and components:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Controller.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123362\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Controller.png\" alt=\"Execution Flow in Controller Mediator Pattern\" width=\"601\" height=\"111\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Controller.png 601w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/Controller-300x55.png 300w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>This approach eliminates the need for mediator-coupling inside the components and offers more centralized control. However, it comes with the price of less modularity which may not be favorable in many situations. Also, it deviates from the traditional intent of the mediator and may closely resemble the observer pattern.<\/p>\n<p>In this article, we will follow the classic approach of a mediator.<\/p>\n<h2>What Problem Does The Mediator Pattern Solve?<\/h2>\n<p>To better understand how the Mediator pattern works, let&#8217;s first talk about the problem it can resolve.<\/p>\n<p>Let&#8217;s imagine a traffic intersection that involves 4 signal points:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/TrafficControlSystem.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123363\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/TrafficControlSystem.png\" alt=\"Flows in Traffic Intersection\" width=\"351\" height=\"341\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/TrafficControlSystem.png 351w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/TrafficControlSystem-300x291.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/a><\/p>\n<p>Signal1 and Signal3 control the traffic moving along north-south. Similarly, Signal2 and Signal4 control the traffic along east-west.\u00a0<\/p>\n<p>For the sake of simplicity, we consider only the basic traffic rule &#8211; <strong>before allowing traffic to move in a particular direction, the traffic moving across that direction must be stopped<\/strong>.\u00a0<\/p>\n<p>Let&#8217;s visualize the provision of this rule when <code>Signal1<\/code> receives a request for the green signal:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/DependencyFlowWithoutMediator-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123364\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/DependencyFlowWithoutMediator-1.png\" alt=\"Dependency Flow Without Mediator Pattern\" width=\"691\" height=\"261\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/DependencyFlowWithoutMediator-1.png 691w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/DependencyFlowWithoutMediator-1-300x113.png 300w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/a><\/p>\n<p>Before showing the green light on <code>Signal1<\/code>, we have to show the red light on <code>Signal2<\/code> and <code>Signal4<\/code>. The same principle applies to all four signal points. As a result, we observe a web of inter-dependencies! Every signal point needs access to other signals leading to a chaotic dependency flow.<\/p>\n<p>The chaos becomes more apparent when we try to implement the signal components based on direct relationships.<\/p>\n<p>The <code>Signal1<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"3,5,6\">public class Signal1() : SignalBase(SignalName.Signal1)\r\n{\r\n    public void ShowGreenLight(Signal2 signal2, Signal4 signal4)\r\n    {\r\n        signal2.ShowRedLight();\r\n        signal4.ShowRedLight();\r\n\r\n        ChangeLight(TrafficLight.Green);\r\n    }\r\n\r\n    public void ShowRedLight() =&gt; ChangeLight(TrafficLight.Red);\r\n}<\/pre>\n<p>The <code>Signal2<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"3,5,6\">public class Signal2() : SignalBase(SignalName.Signal2)\r\n{\r\n    public void ShowGreenLight(Signal1 signal1, Signal3 signal3)\r\n    {\r\n        signal1.ShowRedLight();\r\n        signal3.ShowRedLight();\r\n\r\n        ChangeLight(TrafficLight.Green);\r\n    }\r\n\r\n    public void ShowRedLight() =&gt; ChangeLight(TrafficLight.Red);\r\n}<\/pre>\n<p>To serve the <code>ShowGreenLight()<\/code> request for <code>Signal1<\/code>, we need access to instances of <code>Signal2<\/code>, and <code>Signal4<\/code>. Similarly, <code>Signal2<\/code> implementation depends on <code>Signal1<\/code> and <code>Signal3<\/code>. Because of circular relationships, we can not provide these dependencies as part of the constructor parameters. So we have to supply them as arguments of <code>ShowGreenLight()<\/code> method.<\/p>\n<p>Alternatively, we could explicitly expose the dependent signals as properties and assign them from the client code before invoking <code>ShowGreenLight()<\/code>.\u00a0<\/p>\n<p>Either way, <strong>we end up with a tightly coupled workflow. Any change in the dependency line of any signal component needs to reflect on others as well. Such a design suffers from poor maintainability, less adaptability, and a higher risk of bugs.<\/strong>\u00a0<\/p>\n<p>The mediator pattern effectively addresses this problem by offering a central point of all inter-communications:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/FlowWithMediator.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-123365\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/FlowWithMediator.png\" alt=\"Dependency Flow With Mediator Pattern\" width=\"341\" height=\"281\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/FlowWithMediator.png 341w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/08\/FlowWithMediator-300x247.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/a><\/p>\n<p>By using a <code>TrafficMediator<\/code>, we can centralize the logic of signal interactions and break the web of dependencies!<\/p>\n<h2>Implementation of Mediator Pattern in C#<\/h2>\n<p>So, let&#8217;s refactor our traffic-control system using the mediator pattern.<\/p>\n<p>To begin, we need a contract for the mediator:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public interface ITrafficMediator\r\n{\r\n    void RequestClearance(SignalName signalName);\r\n}<\/pre>\n<p>The <code>ITrafficMediator<\/code> interface defines a method that will hold the interaction logic when a signal requests clearance.<\/p>\n<p>Since all our signal components exhibit the same behavior, we can place the core in a base class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"7-12\">public abstract class SignalBase(ITrafficMediator mediator, SignalName name)\r\n{\r\n    public SignalName Name =&gt; name;\r\n\r\n    public TrafficLight Light { get; private set; }\r\n\r\n    public void ShowGreenLight()\r\n    {\r\n        mediator.RequestClearance(Name);\r\n\r\n        ChangeLight(TrafficLight.Green);\r\n    }\r\n\r\n    \/\/ omitted for brevity\r\n}<\/pre>\n<p>The default constructor lets us initialize the necessary properties. Additionally, this time we also pass the mediator as a constructor dependency.<\/p>\n<p>Talking about the refactored <code>ShowGreenLight()<\/code> implementation &#8211; instead of calling other signal components, we request the mediator for signal clearance. All inter-communication logic will go inside the mediator.\u00a0<\/p>\n<p>The concrete signal classes are now just one-liner codes varied by their <code>Name<\/code> only.<\/p>\n<p>The <code>Signal1<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Signal1(ITrafficMediator mediator) : SignalBase(mediator, SignalName.Signal1) { }<\/code><\/p>\n<p>The <code>Signal2<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Signal2(ITrafficMediator mediator) : SignalBase(mediator, SignalName.Signal2) { }<\/code><\/p>\n<p>And so on.<\/p>\n<p>Finally, it&#8217;s time to implement the concrete mediator:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class TrafficMediator : ITrafficMediator\r\n{\r\n    private Signal1? _signal1;\r\n    private Signal2? _signal2;\r\n    private Signal3? _signal3;\r\n    private Signal4? _signal4;\r\n\r\n    public void Register(Signal1 signal1, Signal2 signal2, Signal3 signal3, Signal4 signal4)\r\n    {\r\n        _signal1 = signal1;\r\n        _signal2 = signal2;\r\n        _signal3 = signal3;\r\n        _signal4 = signal4;\r\n    }\r\n\r\n    public void RequestClearance(SignalName signalName)\r\n    {\r\n        switch (signalName)\r\n        {\r\n            case SignalName.Signal1:\r\n            case SignalName.Signal3:\r\n                _signal2?.ShowRedLight();\r\n                _signal4?.ShowRedLight();\r\n                break;\r\n            case SignalName.Signal2:\r\n            case SignalName.Signal4:\r\n                _signal1?.ShowRedLight();\r\n                _signal3?.ShowRedLight();\r\n                break;\r\n            default:\r\n                throw new InvalidOperationException($\"Unrecognized signal - {signalName}\");\r\n        }\r\n    }\r\n}<\/pre>\n<p>By using <code>Register()<\/code> method, we can establish the connection to the participating signals. And the most interesting bit, the core communication logic, goes inside the <code>RequestClearance()<\/code> method.<\/p>\n<p>Inside the <code>RequestClearance()<\/code> method, we can decide which signals need to be turned off based on the requesting <code>SignalName<\/code>.\u00a0 Anytime we need a change in interaction logic such as introducing new signal points, we can do that by revising <code>RequestClearance()<\/code> method!\u00a0<\/p>\n<p>This is how a mediator can help us control a system of interlaced dependencies.<\/p>\n<h3>Verify the Execution Flow<\/h3>\n<p>Our traffic-control system is ready.<\/p>\n<p>Let&#8217;s set up the mediator and request the green light on <code>Signal1<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var mediator = new TrafficMediator();\r\n\r\nvar signal1 = new Signal1(mediator);\r\nvar signal2 = new Signal2(mediator);\r\nvar signal3 = new Signal3(mediator);\r\nvar signal4 = new Signal4(mediator);\r\n\r\nmediator.Register(signal1, signal2, signal3, signal4);\r\n\r\nsignal1.ShowGreenLight();<\/pre>\n<p>As we inspect the execution flow:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Signal2 is Red\r\nSignal4 is Red\r\nSignal1 is Green<\/pre>\n<p>We see all related signals are notified and reflect the desired traffic light.<\/p>\n<h2>Drawbacks of Mediator Pattern<\/h2>\n<p>Although the mediator contributes to loose coupling and centralized communication control, it has some drawbacks too.<\/p>\n<p>Introducing a mediator means introducing an additional layer of indirection. This also means extra complexity, maintenance overhead, and difficulty in testing.\u00a0<\/p>\n<p>Indirect interaction is usually subjected to additional conditions and is likely to be slower than direct interaction. So the performance overhead can be a potential concern for a complex mediator.\u00a0<\/p>\n<p>Because of centralized communication logic, the mediator may turn to a big monolithic class when many interacting events are involved. Such cases are difficult to maintain and prone to side effects.<\/p>\n<p>In short, the mediator pattern is not a silver bullet. It can bring more problems than it solves if not carefully designed.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we learned how to use the Mediator design pattern in a C# application and how this pattern can reduce the web of dependencies. We have also discussed some factors we should consider while using such patterns.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0In this article, we are going to talk about a popular design pattern, the Mediator Pattern. We will see how this pattern helps address some design problems and how to implement it in C#. Let\u2019s start. What is The Mediator Design Pattern? Mediator is a behavioral design pattern that promotes loose coupling by eliminating chaotic [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":62190,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,504],"tags":[1811,2088,482,778],"class_list":["post-121141","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-design-pattern","tag-c","tag-csharp","tag-design-pattern","tag-mediator","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mediator Design Pattern in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"Explain how the Mediator design pattern can be utilized in a C# application including examples and illustration\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mediator Design Pattern in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Explain how the Mediator design pattern can be utilized in a C# application including examples and illustration\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-16T02:55:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ahsan Ullah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ahsan Ullah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\"},\"author\":{\"name\":\"Ahsan Ullah\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0\"},\"headline\":\"Mediator Design Pattern in C#\",\"datePublished\":\"2024-09-16T02:55:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\"},\"wordCount\":1166,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png\",\"keywords\":[\"C#\",\"csharp\",\"Design Pattern\",\"Mediator\"],\"articleSection\":[\"C#\",\"Design Pattern\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\",\"url\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\",\"name\":\"Mediator Design Pattern in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png\",\"datePublished\":\"2024-09-16T02:55:15+00:00\",\"description\":\"Explain how the Mediator design pattern can be utilized in a C# application including examples and illustration\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Design Patterns\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mediator Design Pattern in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0\",\"name\":\"Ahsan Ullah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg\",\"caption\":\"Ahsan Ullah\"},\"description\":\"A Senior IT Developer with demonstrated proficiency (10+ years of experience) in supply chain management software projects of DSV A\/S. Senior member of the core development team helping to meet growing business demands. Competent in the .NET platform and Angular applications. Other expertise includes skills in database development, designing algorithms, and developing interfaces from low-level responsive html tools to high-level middleware services.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/md-ahsan-ullah-665aa7215\/\"],\"url\":\"https:\/\/code-maze.com\/author\/aullah\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mediator Design Pattern in C# - Code Maze","description":"Explain how the Mediator design pattern can be utilized in a C# application including examples and illustration","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/","og_locale":"en_US","og_type":"article","og_title":"Mediator Design Pattern in C# - Code Maze","og_description":"Explain how the Mediator design pattern can be utilized in a C# application including examples and illustration","og_url":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/","og_site_name":"Code Maze","article_published_time":"2024-09-16T02:55:15+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png","type":"image\/png"}],"author":"Ahsan Ullah","twitter_card":"summary_large_image","twitter_creator":"@CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Ahsan Ullah","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/"},"author":{"name":"Ahsan Ullah","@id":"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0"},"headline":"Mediator Design Pattern in C#","datePublished":"2024-09-16T02:55:15+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/"},"wordCount":1166,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png","keywords":["C#","csharp","Design Pattern","Mediator"],"articleSection":["C#","Design Pattern"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/","url":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/","name":"Mediator Design Pattern in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png","datePublished":"2024-09-16T02:55:15+00:00","description":"Explain how the Mediator design pattern can be utilized in a C# application including examples and illustration","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-mediator-design-pattern\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-design-patterns.png","width":1100,"height":620,"caption":"C# Design Patterns"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-mediator-design-pattern\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Mediator Design Pattern in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/90ad30bf08ba4a2ee4d4489a005da7e0","name":"Ahsan Ullah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/ahsan-ullah-profile-150x150.jpeg","caption":"Ahsan Ullah"},"description":"A Senior IT Developer with demonstrated proficiency (10+ years of experience) in supply chain management software projects of DSV A\/S. Senior member of the core development team helping to meet growing business demands. Competent in the .NET platform and Angular applications. Other expertise includes skills in database development, designing algorithms, and developing interfaces from low-level responsive html tools to high-level middleware services.","sameAs":["https:\/\/www.linkedin.com\/in\/md-ahsan-ullah-665aa7215\/"],"url":"https:\/\/code-maze.com\/author\/aullah\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/121141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=121141"}],"version-history":[{"count":3,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/121141\/revisions"}],"predecessor-version":[{"id":123360,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/121141\/revisions\/123360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62190"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=121141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=121141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=121141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}