Skip to content

Commit

Permalink
Add README for Mediator Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
AliDeWeb committed Mar 9, 2025
1 parent c950922 commit 392dfbf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 08_Mediator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 🔄 Mediator Pattern

## 📌 What is the Mediator Pattern?

The **Mediator Pattern** defines an object (**Mediator**) that encapsulates how a set of objects (**Colleagues**) interact with each other. Instead of objects communicating **directly**, they interact **through the mediator**, reducing dependencies between them. 🔄

This pattern promotes **loose coupling** by centralizing communication logic in a single place. 🏗️

## 🛠️ Key Concepts:

1. **Mediator** → Defines communication rules between objects.
2. **Concrete Mediator** → Manages object interactions.
3. **Colleagues** → Objects that rely on the mediator to communicate.

## 🔥 When to Use?

✅ When multiple objects interact **frequently**, causing a **complex dependency graph**.
✅ When you want to **centralize communication logic** and **reduce coupling**.
✅ When you need to simplify **event-driven interactions**.

## 🎯 Real-World Examples:

- **Chat Rooms**: Users communicate via a chat server 💬
- **Air Traffic Control**: Pilots communicate through a control tower ✈️
- **UI Components**: Buttons, forms, and dialogs interact via a central manager 🎛️

---

🔗 **Example Code:** [See Implementation](./mediator.ts)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ These patterns focus on object creation mechanisms to increase flexibility and r
| **Template Method** | [📜 README](05_Template_Method/README.md) |
| **Command** | [📜 README](06_Command/README.md) |
| **Observer** | [📜 README](07_Observer/README.md) |
| **Mediator** | [📜 README](08_Mediator/README.md) |

0 comments on commit 392dfbf

Please sign in to comment.