Monday, April 22, 2024

Mediator Design Pattern in C#

The Mediator Design Pattern is a behavioral design pattern that promotes loose coupling between objects by encapsulating how they interact. It centralizes complex communication logic between multiple objects into a mediator object, thus reducing direct dependencies between them. This promotes easier maintenance and scalability of the system.

The Mediator Design Pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object. This pattern is used to centralize complex communications and control between related objects in a system. The Mediator object acts as the communication center for all objects. That means when an object needs to communicate with another object, it does not call the other object directly. Instead, it calls the mediator object, and it is the responsibility of the mediator object to route the message to the destination object.

Components of Mediator Design Pattern

  1. Mediator: Defines an interface for communication between colleague objects.
  2. Colleague: It is an abstract class, and Concrete Colleague classes will implement this abstract class.
  3. ConcreteMediator: Implements the mediator interface, coordinating communication between colleague objects.
  4. ConcreteColleague: Implements the colleague interface and communicates with other colleagues through the mediator.

Sunday, April 14, 2024

Template Method Design Pattern in C#

The Template Method Design Pattern is a behavioral design pattern that defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure. It allows reusing common behavior across multiple classes while still allowing customization where necessary.

Components of Template Method Design Pattern

  • Abstract Class: This class defines the template method, which is the skeleton of the algorithm. It consists of several abstract methods that subclasses must implement.
  • Concrete Classes: These classes inherit from the abstract class and provide implementations for the abstract methods.

Monday, April 8, 2024

Command Design Pattern in C#

The Command Design Pattern is a behavioral design pattern that encapsulates a request as an object, thereby allowing parameterization of clients with queues, requests, and operations. This pattern decouples sender and receiver of a request based on a command, which helps in invoking the right method at the right time without knowing the actual implementation details.

Components of Command Design Pattern

  1. Command: Defines an interface for executing an operation.
  2. Concrete Command: Implements the Command interface and binds a receiver with an action. It defines a binding between the action and the receiver.
  3. Invoker: Requests the command to execute the operation.
  4. Receiver: Knows how to perform the operation.

Sunday, March 24, 2024

Observer Design Pattern in C#

The Observer Design Pattern is a behavioral design pattern that defines a one-to-many dependency between objects. When one object (the subject) changes its state, all its dependents (observers) are notified and updated automatically. This pattern is widely used in software engineering to establish communication between objects in a loosely coupled manner.

This Design Pattern is widely used for implementing distributed event-handling systems where an object needs to notify other objects about its state changes without knowing who these objects are.

In the Observer Design Pattern, an object (called a Subject) maintains a list of its dependents (called Observers). It notifies them automatically whenever any state changes by calling one of their methods. The Other names of this pattern are Producer/Consumer and Publish/Subscribe.

Components of Bridge Design Pattern

  1. Subject: This is the object that is being observed. It maintains a list of observers and provides methods to attach, detach, and notify observers of state changes.
  2. Observer: This is the interface that defines the method(s) that the subject will use to notify observers of state changes.
  3. ConcreteSubject: This is the concrete implementation of the subject. It maintains the state of interest and notifies observers when changes occur.
  4. ConcreteObserver: This is the concrete implementation of the observer. It registers itself with the subject and implements the update method to react to changes in the subject's state.
^ Scroll to Top