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.

Monday, April 1, 2024

Strategy Design Pattern in C#

The Strategy Design Pattern is a Behavioral Design Pattern that enables selecting an algorithm’s behavior at runtime. Instead of implementing a single algorithm directly, run-time instructions specify which of a family of algorithms to use.

This pattern is ideal when you need to switch between different algorithms or actions in an object dynamically. That means the Strategy Design Pattern is used when we have multiple algorithms (solutions) for a specific task, and the client decides which algorithm to use at runtime.

Components of Strategy Design Pattern

  1. Strategy Interface: This defines a set of methods that represent the algorithms. It acts as a contract for all concrete strategy classes.
  2. Concrete Strategies: These are the actual implementations of the algorithms defined in the strategy interface.
  3. Context: This is the class that uses the strategy. It contains a reference to the strategy interface and can switch between different strategies dynamically.

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.

Thursday, February 15, 2024

Standalone Components in Angular

Standalone Components in Angular

A standalone component is a type of component that doesn’t belong to any specific Angular module.Before Angular version 14, when you created a component, you typically had to include it in the declaration array of a module; otherwise, Angular would throw an error during compilation.Standalone components are independent units that can be instantiated and used anywhere within an Angular application, regardless of the module structure. Standalone components can be useful for creating reusable UI elements or utility functions that are not specific to any module.

In this post, we'll explore standalone components in Angular and how to create them with a detailed example.

Creating a Standalone Component

First, make sure you're using Angular version 14. To create a component on its own, use the --standalone option with the command ng generate component.

ng g c component_name  --standalone

Sunday, February 4, 2024

Decorators in Angular

Decorators in Angular

There are several important concepts in Angular, and Decorators are an important concept to learn when you are working Angular. Decorators in Angular are a powerful and essential feature used to enhance and modify the behavior of classes, methods, and properties. Through this post we will learn about decorators, its types and how it is being used in real time applications.

What are Decorators?

Decorators are functions that are invoked with a prefixed @ symbol.Basically, a decorator provides configuration metadata that determines how the component, class or a function should be processed, instantiated and used at runtime.Decorators are applied to classes, class properties, and class methods using the following syntax:

@DecoratorName(arguments)

Angular comes with several built-in decorators, and you can also create custom decorators to extend or modify the behavior of your application.

Thursday, January 25, 2024

Bridge Design Pattern in C#

The Bridge Design Pattern is a structural pattern that separates the abstraction from its implementation so that the two can vary independently.This pattern involves an interface that acts as a bridge between the abstraction class and implementer classes. It is useful in scenarios where an abstraction can have several implementations, and you want to separate the implementation details from the abstraction.

Purpose of Bridge Pattern

  • Decouple an abstraction from its implementation so that the two can vary independently.
  • Promote code reusability by allowing the abstraction and implementation to evolve independently.

Sunday, January 21, 2024

Flyweight Design Pattern in C#

The Flyweight design pattern is a structural pattern that focuses on minimizing the memory footprint or computational expenses of an object. It achieves this by sharing as much as possible with related objects, rather than keeping all of the data in each object. This is particularly useful when dealing with a large number of similar objects, as it helps reduce the overall memory consumption and improves performance.

Purpose of Flyweight Pattern:

  • To reduce the number of objects and to conserve memory by sharing objects among multiple contexts.
  • To achieve performance improvement by minimizing the overhead of creating and managing large numbers of similar objects.

Saturday, January 13, 2024

Proxy Design Pattern in C#

The Proxy Design Pattern is a structural design pattern. that provides a surrogate or placeholder for another object to control access to it.

This pattern comes in handy when we want to add an extra layer of control over the access to an object, such as lazy loading, access control, or logging. In C#, the Proxy Design Pattern is commonly used to create a surrogate object that represents another object.

We can also say that the Proxy is the object the client calls to access the real object behind the scene. Proxy means in place of or on behalf of. That means, In the Proxy Design Pattern, a class represents the functionality of another class.

Component of Proxy Design pattern

  • Subject: This is an interface that defines the members that will be implemented by the RealSubject and Proxy class so that the Proxy can be used by the client instead of the RealSubject. In our example, it is the ISharedFolder interface.
  • RealSubject: This is a class that we want to use more efficiently by using the proxy class. This class should implement the Subject Interface. In our example, it is the SharedFolder class.

Friday, January 12, 2024

Composite Design Pattern in C#

The Composite Pattern is a structural design pattern that enables us to treat individual and group objects uniformly by creating a hierarchical (tree-like) structure of objects, where both the composite (groups) objects and leaf (individual) objects share a standard interface.

This pattern lets clients treat individual objects and compositions of objects uniformly. That means the client can access the individual objects or the composition of objects in a uniform manner. It’s useful for representing hierarchical structures such as file systems, UI components, or organizational structures.

What are Composite and Leaf classes?

  1. The Composite Class — represents a group of objects and can contain other objects (i.e. env_item_collection, env_item_collection_parent, env_root), and
  2. the Leaf Class — represents an individual object that cannot contain other objects (i.e. env_item).

Monday, January 8, 2024

Facade Design Pattern in C#

Facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes.It helps encapsulate the complexity of multiple subsystems into a single unified interface.

In software terms, Facade pattern hides the complexities of the systems and provides a simple interface to the clients.

This pattern involves one wrapper class which contains a set of methods available for the client. This pattern is particularly used when a system is very complex or difficult to understand and when the system has multiple subsystems.

Component of Facade Design Pattern

  • Complex System: A library of subsystems.
  • Subsystems: These are classes within a complex system and offer detailed operations.
  • Façade: This is a wrapper class which wrapper class which contains a set of members which are required by the client.
  • Client: This is a class which calls the high-level operations in the Façade.

Tuesday, January 2, 2024

Decorator Design Pattern in C#

The Decorator Design Pattern is a structural pattern in software development that allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.

The idea of the Decorator Pattern is to wrap an existing class, add other functionality to it, then expose the same interface to the outside world. Because of this our decorator exactly looks like the original class to the people who are using it.

It is used to extend or alter the functionality at runtime. It does this by wrapping them in an object of the decorator class without modifying the original object. So it can be called a wrapper pattern.

Components of Decorator Design Pattern

  • Component: It defines the interface of the actual object that needs functionality to be added dynamically to the ConcreteComponents.
  • ConcreteComponent: The actual object in which the functionalities could be added dynamically.
  • Decorator: This defines the interface for all the dynamic functionalities that can be added to the ConcreteComponent.
  • ConcreteDecorator: All the functionalities that can be added to the ConcreteComponent. Each needed functionality will be one ConcreteDecorator class.
^ Scroll to Top