What is the Dotnet Structural Design Pattern?

dotnet structural design pattern


It is concerned with how classes and objects can be composed, to form larger structures. It simplifies structure by identifying the relationship. It is focused on how the classes inherit from each other and how they are composed of other classes.

dotnet web development


Type of SDP

Factory method design pattern is one of the most used design patterns in .NET. It is used to solve the problem related to object creation.

  • Adapter Pattern: Adapting an interface into another according to client expectation.
  • Bridge Pattern: Separating abstraction (interface) from implementation.
  • Composite Pattern: Allowing clients to operate on a hierarchy of objects.
  • Decorator Pattern: Adding functionality to an object dynamically.
  • Facade Pattern: Providing an interface to a set of interfaces.
  • Flyweight Pattern: Reusing an object by sharing it.
  • Proxy Pattern: Representing another object.


Adapter Design Pattern

We can use this pattern “Use different class in your application but that an interface is not compatible and combines the capability”. In simple it is work like a bridge between two incompatible systems. It allows two or more previously incompatible objects to interact. It allows reusability of existing functionality.

It is dependent on Factory Design Pattern for creating objects but it is also two another pattern (Builder Design Pattern & Prototype Design Pattern ) for creating the product. It means that it depends on your implementation of creating products.

For Example:  Card reader – It acts as an adapter between a memory card and a laptop. When you insert in the memory card in card reader after this card reader plugs into the laptop and then you can read data from memory card.

Where to use it?

  • We can use this at where objects need to utilize an existing class with an incompatible interface.
  • Allow communication between a new and already existing system which are independent of each other
  • It is easy to implement and quite common when the legacy code is involved


Bridge Design Pattern

It’s used to create a set of related objects or dependent objects. Abstract Factory use the factory for creating objects of several classes.

In this pattern, abstraction and implementation are separated and so it can be modified independently. It allows the abstraction of a class to be decoupled from its implementation so that both classes can be modified independently.

The Bridge Pattern is also known as Handle or Body.  It hides the implementation details from the client.  It enables the separation of implementation from the interface. It improves extensibility. 

Where to use it?

  • You can use it at where you don’t want a permanent binding between the functional abstraction and its implementation.
  • It is used in those places where changes made in the implementation do not affect the client.


Composite Design Pattern

It creates a tree structure with a group of objects to represent a hierarchy. In the tree structure, every object is responsible to perform the task. The hierarchies of a class contain primitive and complex objects. It is useful when individual objects, as well as a group of those kinds of objects, are treated uniformly.

For Example: Folder Structure Of our computer structure: Each drive contains lots of folders and all folder can also contain subfolder and this all subfolder also contains lots of files. A file from any drive partition you may traverse to down any file by a couple of mouse clicks

Where to use it?

  • You can use it at where you want to represent a full or partial hierarchy of clients.
  • The responsibilities are needed to be added dynamically to the individual objects without affecting other objects. Responsibility can be varying from time to time.


Decorator Design Pattern

It is used to add functionality to an existing object without modifying its current structure. It also provides a flexible alternative to subclassing for extending functionality. It gives new behaviors or operations to an object at run-time by using a wrapper class on to original class.

Where to use it?

  • It provides enhancement to the interface. From this, it enhances an object’s responsibilities so it is more transparent to the client.
  • Add additional state, behavior to an object dynamically. 


Facade Design Pattern

It describes a higher level interface that makes the subsystem easier to use. It hides the complexities of the system and provides an interface to the client. In practically way, every abstract factory is a type of Facade. It shields the complexities to the sub-system components. It promotes loose coupling between subsystems and its clients.

Where to use it?

  • It provides a simple interface to the complex sub-system.
  • Add additional state, behavior to an object dynamically. 


Flyweight Design Pattern

It reduces the number of objects created, to decrease memory and resource usage. As a result, it increases performance. This pattern is reuse already existing similar kind of objects by storing them and creates an object when no matching object is found. It reduces the number of objects. 

It is reduced and a number of objects. It reduces the amount of memory and storage devices required if the objects are persisted.

Where to use it?

  • It is used where an application uses a number of objects.
  • It is used where storage cost is high because of a number of objects.
  • When the application does not depend on object Identity.


Proxy Design Pattern

It used to provide the surrogate object, which references to another object. It involves a class, called proxy class, which represents the functionality of another class. It provides protection to the original object from the outside world.

It is divided in three ways:

  • Remote Proxies: Encodes requests and send them across a network.
  • Virtual Proxies: Hand over the creation of an object to another object.
  • Authentication Proxies: Checks the access permissions for a request.
  • Smart Proxies: Change requests before sending them across a network.

 

Dharmesh Kanzariya
Dharmesh Kanzariya
Diligent and result-oriented IT Professional with an experience of nearly 11 year of experience in Software Development in Dotnet, Java, Node.Js, Nest.Js . Knowledge of all phases of the Software Development Life Cycle from System analytics to deployment.
Related Posts