iT邦幫忙

0

詮釋 behavioral, creational and structural pattern 的概念

  • 分享至 

  • xImage
  •  

這次要來看到~ 設計模式中~ 三種類型(創建、結構、行為)模式的概念~


學習目標: 創建模式、結構模式、行為模式的概念

學習難度: ☆☆☆


Creational design patterns

What is the Creational Design Pattern in C#?

Creational design patterns are design patterns that deal with object creation mechanisms i.e. trying to create objects in a manner that is suitable to a given situation. In simple words, we can say that the Creational Design Pattern deals with Object Creation and Initialization. This Design Pattern gives the programmer more flexibility in deciding which objects need to be created for a given situation.

When to use the Creational Design Pattern?

In real-time applications, the project is created with a lot of classes. A lot of classes mean we are dealing with a lot of objects. So we need to create different objects (like new Customer(), new Product(), new Invoice(), etc.). If the object creations logic based on some condition is implemented in the client code, then it leads to lots of complicated logic in the client code. That means if the object creations and initialization logic are not centralized then it leads to a very complicated code. The Creational Design Pattern helps us to centralized the object creation logic and depending upon the condition, it will create, initialize, and returns the appropriate object to the client.


Structural design patterns

What is Structural Design Pattern in C#?

Structural Design Patterns are design patterns that ease the design by identifying a simple way to realize the relationship among entities. In simple words, we can say that the Structural Design Pattern is basically used to manage the structure of classes and interface as well as manage the relationship between the classes.

When to use Structural Design Patterns in C#?

In real-time applications, sometimes we need to change the structure of a class or the relationship among the classes but we don’t want this change to be affected by the project. For example, if we have two classes let say User and Product. And the Product class is used inside the User class making one-to-many relationships between the User and Product. Tomorrow, the structure or the relationships between these two classes change. The customer now wants to keep away the Product class from the User class, as they want to use the User and Product class independently. This is actually a structural change and we don’t want this structural change to affect our project. This is where the Structural Design Pattern helps us.


Behavioral design patterns

What is Behavioral Design Pattern in C#?

Behavioral design patterns are design patterns that identify common communication patterns among objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.

The Behavioral Design Patterns deal with the communication or interaction between Classes and objects. The interaction between the objects should be in such a way that they are talking to each other and still are loosely coupled. The loose coupling is the key to n-tier architecture.

So, a behavioral pattern explains how objects interact.** It describes how different objects and classes send messages to each other to make things happen** and how the steps of a task are divided among different objects.

When to use Behavioral Design Patterns in C#?

In real-time applications, sometimes we want to change the behavior of a class and again we don’t want it to affect other classes of the project. For example, we have an Invoice class that currently applying taxes as 18%. Tomorrow if we want to add another extra tax. That means we are changing the behavior of a class. To solve such types of Behavioral issues Behavioral Design Pattern comes into the picture.


https://dotnettutorials.net/lesson/structural-design-pattern/

https://dotnettutorials.net/lesson/behavioral-design-pattern/

https://dotnettutorials.net/lesson/behavioral-design-pattern/


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言