826 热度

How to use the Strategy Pattern in C#

The Strategy Pattern is a Behavioral Pattern , software Design Patterns defined by the Gang of Four in Design Patterns: Elements of Reusable Object-Oriented Software , it is also discussed in Head First Design Patterns.

收录时间: 2022-04-26
分类: 设计模式
贡献者: Rector
870 热度

Visitor Design Pattern in C#

The Visitor pattern allows decoupling algorithms from the objects on which they operate. It allows adding and changing functionalities in a type-safe and SOLID manner. This is one of the most complex classic design patterns. In this article, we’ll discuss how it’s structured, what value it brings, as well as what are the tradeoffs and alternatives. We are also going to mention several variations of the implementation of the pattern.

收录时间: 2022-02-09
分类: 设计模式
贡献者: Rector
995 热度

The Mediator Pattern

The Mediator Pattern one of the Behavioral Patterns defined by the Gang of Four in Design Patterns: Elements of Reusable Object-Oriented Software. Mediator pattern is used to reduce communication complexity between multiple objects or classes. The pattern provides a mediator class which handles all the communications between different classes and supports easy maintenance of the code by loose coupling. A mediator sits between method callers and receivers creating a configurable layer of abstraction that determines how callers and receivers get wired up.

收录时间: 2021-05-20
分类: 设计模式
贡献者: Rector
940 热度

The Adapter Pattern

The Adapter Pattern is the first software design pattern of the Structural Pattern, that the Gang of Four (GOF) Design Patterns, presented in their book , Design Patterns – Elements of Reusable Object-Oriented Software.

收录时间: 2021-05-06
分类: 设计模式
贡献者: Rector
1226 热度

Mediator Pattern Using .NET

In this post, I will show how to implement a Mediator pattern using .NET/C# to help write loosely coupled code.

收录时间: 2020-12-09
分类: 设计模式
贡献者: Rector
1371 热度

Design patterns in C# - The Proxy Pattern

Continuing my series on design patterns, this week we're focusing on the proxy pattern! The proxy pattern is used to provide access to an object. It is often used to enable this access over some distance - this could be providing remote access, or adding an extra level of protection around the object. The crucial thing is that the proxy pattern offers a way to indirectly provide (and control) access. It is similar in implementation to the decorator pattern, but its purpose is different. Both patterns wrap an inner object, however the decorator pattern expands on the functionality of the inner object, where the proxy pattern instead governs the access to the object.

收录时间: 2020-12-09
分类: 设计模式
贡献者: Rector
AD 友情赞助
1179 热度

C#设计模式之适配器模式

适配器模式,简单来说,就是将一个类的接口转换为另外一个类的接口,使得原本由于接口不兼容而不能一起工作的那些类能够一起工作。在现实生活中,这种例子也很多,比如我们如果买的是港行的电器,比如港版的iPhone,英版的原版树莓派,那么自带的充电器插头可能就是英标,在国内不能直接使用,国标的插头间距跟英标不兼容,所以,就需要一个适配器。

收录时间: 2020-12-01
分类: 设计模式
贡献者: Rector
1174 热度

C#设计模式-原型模式(Prototype Pattern)

在软件开发过程中,我们习惯使用new来创建对象。但是当我们创建一个实例的过程很昂贵或者很复杂,并且需要创建多个这样的类的实例时。如果仍然用new操作符去创建这样的类的实例,会导致内存中多分配一个一样的类实例对象,增加创建类的复杂度和消耗更多的内存空间。 如果采用简单工厂模式来创建这样的系统。随着产品类增加,子类数量不断增加,会增加额外系统复杂程度,为此我们不得不引入原型模式了。

收录时间: 2020-11-20
分类: 设计模式
贡献者: Rector
1063 热度

23种设计模式之七种结构型模式从概念介绍再到案例分析,不懂就从例子去感受

二、结构型模式(Structure Pattern)1.适配器模式将一个类的接口转换成客户希望的另外一个接口,使得不能兼容的而能在一起工作。(1)类的适配器:当希望将一个类转换成另一个新接口的类时,可以使用类的适配器模式,创建一个新类,继承原来的类,实现新的接口。举例:电脑网线接口(目标接口)、网线(需要适配的类)和网线适配器(适配器)。此时应该时将网线转换成电脑网线接口,我们用类的适配器实现类去继承网线类并实现抽象出来的适配器接口——相当于把网线插在了适配器上。

收录时间: 2020-11-02
分类: 设计模式
贡献者: Rector
1253 热度

Design patterns in C# - The Adapter Pattern

Hello again, in this post I'm continuing my series on design patterns in C#, this time focusing on the adaptor pattern! The adapter pattern is useful when you want to use a class that does not fit the design of your existing solution. This is often the case when using legacy or external code. The adapter pattern allows you to define a wrapper which executes the desired behaviour, but exposes it through a method which your solution expects. As always, I think this will become clearer when we delve into our (dinosaur-based) example.

收录时间: 2020-10-23
分类: 设计模式
贡献者: Rector
1835 热度

Design patterns in C# - The Decorator Pattern

So, after a long break, this week I've decided to revive my series on design patterns in C#, and move on to the decorator pattern! To use the decorator pattern, you wrap an object in another object in order to extend behaviour. The objects all implement the same interface, so the decorators can stack on top of one another, extendng the behaviour further. Using this pattern, you are able to extend the behaviour of a single object, rather than extending the behaviour of a class as a whole (by e.g. using subclasses).

收录时间: 2020-10-16
分类: 设计模式
贡献者: Rector
1595 热度

C#实践设计模式原则SOLID

理论跟实践的关系,说远不远,说近不近。能不能把理论用到实践上,还真不好说。通常讲到设计模式,一个最通用的原则是SOLID:S - Single Responsibility Principle,单一责任原则O - Open Closed Principle,开闭原则L - Liskov Substitution Principle,里氏替换原则I - Interface Segregation Principle,接口隔离原则D - Dependency Inversion Principle,依赖倒置原则嗯,这就是五大原则。后来又加入了一个:Law of Demeter,迪米特法则...

收录时间: 2020-08-20
分类: 设计模式
贡献者: Rector
1438 热度

让对象拥有状态——C#中的状态模式

大家好,老胡又在博客和大家见面了,在聊今天的主角之前,老胡先给大家讲一个以前发生的故事。真实的故事当老胡还是小胡的时候,跟随团队一起开发一款游戏。这款游戏是一款末日生存类游戏,玩家可以收集资源,两种,一种金子,一种铁。升级自身击杀敌人用资源合成装备项目开发的很顺利,我那时得到一个任务,是为游戏做一个新手教程,在这个教程里面,通过一系列步骤,引导新手玩家熟悉这个游戏。游戏设计给出的教程包含以下步骤收集金子收集铁击杀敌人升级同时要求在不用的阶段显示不同的提示以正确引导玩家。考虑合成装备算是高级玩家才会接触到的功能,所以暂时不打算放在新手教程里面。当老大把任务交给我的时候,我感觉简单爆了,不就写一个...

收录时间: 2020-07-02
分类: 设计模式
贡献者: Rector
1117 热度

C#中的Singleton模式

Singleton是二十三个设计模式中比较重要也比较经常使用的模式。但是这个模式虽然简单,实现起来也会有一些小坑,让我们一起来看看吧!

收录时间: 2020-06-05
分类: 设计模式
贡献者: Rector
1637 热度

如何在C#/.NET Core中使用责任链模式

最近我有一个朋友在研究经典的“Gang Of Four”设计模式。他经常来询问我在实际业务应用中使用了哪些设计模式。单例模式、工厂模式、中介者模式 - 都是我之前使用过,甚至写过相关文章的模式。但是有一种模式是我还没有写过文章,即责任链模式。什么是责任链?责任链模式(之前我经常称之为命令链模式)是一种允许以使用分层方式”处理“对象的模式。在维基百科中的经典定义是在面向对象设计中,责任链模式是一种由命令对象源及其一系列处理对象组成的设计模式。每个处理对象包含了它...

收录时间: 2020-05-08
分类: 设计模式
贡献者: Rector
AD 友情赞助
1197 热度

代理模式是什么?如何在 C# 中实现代理模式

代理模式并不是日常开发工作中常常用到的一种设计模式,也是一种不易被理解的一种设计模式。但是它会广泛的应用在系统框架、业务框架中。定义它的 定义 就如其它同大部分 设计模式 的定义类似,即不通俗也不易懂,而且随便百度一下就能找到 : 为其他对象提供一种代理,以控制对这个对象的访问。代理对象在客户端和目标对象之间起到中介的作用。每个字都认识,连在一起就看不懂了 by. 某个攻城狮我们一个词一个词看就明白了。其他对象所谓的 其它,其实就是你系统中 任意 一个类型...

收录时间: 2020-04-23
分类: 设计模式
贡献者: Rector
1627 热度

Design Pattern in C# - Facade Pattern

In this article, we are about to cover another design pattern in C#, this time a structural one. That pattern is the Facade Pattern.The source code is available at the Facade Design Pattern GitHub Repository. For the complete list of articles from this series check out C# Design Patterns.To begin wit...

收录时间: 2020-03-25
分类: 设计模式
贡献者: Rector
2301 热度

Command Design Pattern Explained with C# Examples

The command pattern is a behavioral design pattern. This pattern encapsulates a request as an object that contains all the information about the request, including requests for queues or logs, allowing for much more complex architectures. It even allows operations like undo and redo. In this blog post, we’ll learn how to implement the command pattern in C# and we’ll see in which use cases it can be useful.

收录时间: 2020-02-28
分类: 设计模式
贡献者: Rector
2231 热度

Singleton Design Pattern In C#

In this article, learn what a Singleton Design Pattern is and how to implement a Singleton Pattern in C#. facebooktwitterlinkedInRedditWhatsAppEmailBookmarkPrintOther ArtcileExpandSingleton.zipSingleton Design Pattern In C#   Design patterns are a vital part of software design and architectu...

收录时间: 2020-02-21
分类: 设计模式
贡献者: Rector
1447 热度

从壹开始 [ Design Pattern ] 之一 ║ 设计模式开篇讲

不说其他的没用的开场白了,直接给大家分享三个小故事,都来自于我的读者粉丝(我厚着脸皮称为粉丝吧 ):问题一:半年前开始学 netcore,现在学东西还是有些吃力,老是报错,比如Autofac,而且还老是找不到解决办法,找到了吧,可能下次还是出错,学习也是断断续续的,但是公司还是用 .net ,心累。问题二:说自己跟着我的文章还有项目,学了 NetCore 也有一段时间了,基本都能看懂,但是学到了 DDD 以后,自己动手搭建,发现一直品不出来味道,仿佛又回到了当时用动软代码生成器生成三层代码的时代了,心慌;问题三:现在啥基本都会点儿,但是不是很懂原理,比如 Autofac 现在我基本都...

收录时间: 2019-11-22
分类: 设计模式
贡献者: Rector
AD 友情赞助