诠释 behavioral, creational and structural pattern 的概念

这次要来看到~ 设计模式中~ 三种类型(创建、结构、行为)模式的概念~


学习目标: 创建模式、结构模式、行为模式的概念

学习难度: ☆☆☆


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/


<<:  解决xampp中mysql的admin介面打不开

>>:  AWS Lambda 搭配 Amazon API Gateway

【从实作学习ASP.NET Core】Day22 | 前台 | 商品留言板

拍卖网站通常会设有 Q&A 留言板,方便买家跟店家交流,像是问有没有现货之类的。 今天就试着...

Microsoft AZ-900 Dumps - The Greatest Shortcut Towards Success

Microsoft AZ-900 exam preparation is tough but you...

[Day21] Tableau 轻松学 - Parameter

前言 有的时候我们会想让使用者输入一些参数,根据这些参数来做筛选或运算。到目前为止,我们没使用到这个...

介绍Vertex(1) | ML#Day18

Day1 的时候有提到我们公司使用的云端方案是GCP (Google Cloud Platform)...