1709 热度

The Prototype Design Pattern C# .net core

The Prototype Design Pattern is one of the Creational Design Patterns defined by the Gang Of Four (GOF) published their book Design Patterns: Elements of Reusable Object-Oriented Software in which they presented a catalog of simple and succinct solutions to commonly occurring design problems.

收录时间: 2019-10-30
分类: 设计模式
贡献者: Rector
1533 热度

Composite command pattern

I have previously blogged about command pattern and composite pattern. I had some projects where I succesfully mixed these two together to compose a composite command. It’s a construct to have a commands hierarchy we can execute with one shot.

收录时间: 2019-10-29
分类: 设计模式
贡献者: Rector
2981 热度

依赖倒置原则(DIP)、控制反转(IoC)、依赖注入(DI)(C#)

理解:依赖倒置原则(DIP)主程序要依赖于抽象接口,不要依赖于具体实现。高层模块不应该依赖底层模块,两个都应该以来抽象。抽象不应该依赖细节,细节应该依赖抽象。(具体看我上一篇贴子)依赖倒置原则是六大设计原则中的一种,它的大致意思是所有模块都应该依赖于抽象,而不是直接依赖于另一个模块。依赖倒置原则仅仅只是一个原则而已,它只是告诉了你程序应该要变成什么样子(模块之间依赖抽象),而并没有具体告诉你应该怎么做。就像是在学校,老师告诉你教室要干净,不要有垃圾,而具体打扫垃圾的动作老师却并没有告诉你,你可以选择用扫把打扫,也可以选择用手捡,但是最终教室要干净(当然,你也可以不遵守)。控制反转(IoC)就是...

收录时间: 2019-09-06
分类: 设计模式
贡献者: Rector
1510 热度

六大设计原则(C#)

为什么要有设计原则,我觉得一张图片就可以解释这一切一、单一职责原则(SRP)对于一个类而言,应该只有一个发生变化的原因。(单一职责不仅仅是指类)如果一个模块需要修改,它肯定是有原因的,除此原因之外,如果遇到了其他情况,还需要对此模块做出修改的话,那么就说这个模块就兼具多个职责。

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

My 5 Favorite Software Design Principles

Here are 5 of my favorite software design principles that have really helped my career. It not only helped me build better software but helped me understand the craft and relieve a lot of frustration.

收录时间: 2019-08-13
分类: 设计模式
贡献者: Rector
1618 热度

Object-Oriented Programming

OOP is considered by many to be the crown jewel of computer science. The ultimate solution to code organization. The end to all our problems. The only true way to write our programs. Bestowed upon us by the one true God of programming himself…

收录时间: 2019-07-26
分类: 设计模式
贡献者: Rector
AD 友情赞助
1517 热度

C# Design Patterns: The Strategy Pattern

In this article I’m going to introduce and talk about the Strategy Pattern. It’s a common design pattern that helps your program maintain flexibility in the midst of diverse requirements.

收录时间: 2019-06-27
分类: 设计模式
贡献者: Rector
1787 热度

Refactoring switch case statement into strategy design pattern

A strategy design pattern is the most commonly used design pattern in computer programming. In this post, we’ll refactor a switch case into a strategy design pattern. We’ll start with a basic switch case statement and then we’ll gradually refactor the code into strategy design pattern.

收录时间: 2019-04-19
分类: 设计模式
贡献者: Rector
1648 热度

C#单例类的实现

C#单例类的实现单例类保证一个类全局仅有一个实例,并提供一个全局访问点,由于只能生成一个实例,因此我们必须把构造函数设为私有函数以禁止他人创建实例。实现1:懒汉式,线程不安全该实现没有额外开销,不要求线程安全的情况下可以使用:public class Singleton1{private static Singleton1 instance = null;private Singleton...

收录时间: 2019-04-11
分类: 设计模式
贡献者: Rector
1969 热度

C# Design Patterns - Strategy

The Strategy design pattern is a behavioral design pattern which allows us to define different functionalities, put each functionality in a separate class and make their objects interchangeable. In other words, we have a main Context object that holds a reference towards a Strategy object and delegates it by executing its functionality. If we want to change the way the Context performs its work, we can just replace the current Strategy object with another one.

收录时间: 2019-04-09
分类: 设计模式
贡献者: Rector
2466 热度

C# Design Patterns - Command Design Pattern

The Command pattern is a behavioural design pattern that we can use to turn a request into an object which contains all the information about the request. The Command design pattern is quite popular in C#, especially when we want to delay or queue a request’s execution or when we want to keep track of our operations. Furthermore, this possibility to keep track of our operations gives us the opportunity to undo them as well.

收录时间: 2019-04-02
分类: 设计模式
贡献者: Rector
1973 热度

C# Design Patterns - Decorator Design Pattern

In this article, we are going to talk about another structural C# design pattern, the Decorator Design Pattern. We are going to learn, how to implement this pattern in our project and what we can get by doing that. The source code is available at the Decorator Design Pattern – Source Code.

收录时间: 2019-03-27
分类: 设计模式
贡献者: Rector
1789 热度

C#设计模式:六大原则(上)

面向对象设计原则,是一种指导思想,在程序设计过程中,要尽量的去遵守这些原则,用于解决面向对象设计中的可维护性,可复用性以及可扩展性。常用的,就是我们日常所说的6大原则,分别是:单一职责(SRP)、里氏替换原则(LSP)、依赖倒置原则(DIP)、接口隔离原则(ISP)、迪米特法则(LOD)、开闭原则(OCP)。下面就来分别说说这些原则:一、 单一职责(Single Reponsibility P...

收录时间: 2018-09-18
分类: 设计模式
贡献者: Rector
1904 热度

Strategy Pattern Implementations In C#: Basic To Advanced

Let's look at some different ways you could implement the strategy pattern in C#. First, I'd like to briefly mention why we care about design patterns and where the strategy pattern fits in. Why Should I Know The Strategy Pattern? Understanding design patterns is a vital skill to possess as a software developer and/or software architect. If you don't, then you end up

收录时间: 2018-08-28
分类: 设计模式
贡献者: Rector
2017 热度

【设计模式】适配器模式 Adapter Parttern

【设计模式】适配器模式 Adapter Parttern2018-08-08 08:37 by 蓝之风, ... 阅读, ... 评论, 收藏, 编辑适配器模式在软件开发界使用及其广泛,在工业界,现实中也是屡见不鲜。比如手机充电器,笔记本充电器,广播接收器,电视接收器等等。都是适配器。 适配器主要作用是让本来不兼容的两个事物兼容和谐的一起工作。比如, 通常我们使用的交流电都是220v,但...

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

依赖注入[3]: 依赖注入模式

IoC主要体现了这样一种设计思想:通过将一组通用流程的控制权从应用转移到框架中以实现对流程的复用,并按照“好莱坞法则”实现应用程序的代码与框架之间的交互。我们可以采用若干设计模式以不同的方式实现IoC,比如我们在《依赖注入[2]: 基于IoC的设计模式》介绍的模板方法、工厂方法和抽象工厂,接下来我们介绍一种更为有价值的IoC模式,即依赖注入(DI:Dependency Injection,以下简称...

收录时间: 2018-07-27
分类: 设计模式
贡献者: Rector
2129 热度

依赖注入[2]: 基于IoC的设计模式

依赖注入[2]: 基于IoC的设计模式正如我们在《控制反转》提到过的,很多人将IoC理解为一种“面向对象的设计模式”,实际上IoC自身不仅与面向对象没有必然的联系,它也算不上是一种设计模式。一般来讲,设计模式提供了一种解决某种具体问题的方案,但是IoC既没有一个针对性的问题领域,其自身没有提供一种可实施的解决方案,所以我更加倾向于将IoC视为一种设计原则。实际上很多我们熟悉的设计模式背后采用了Io...

收录时间: 2018-07-26
分类: 设计模式
贡献者: Rector
1658 热度

【设计模式】工厂方法模式 Factory Method Pattern

在简单工厂模式中产品的创建统一在工厂类的静态工厂方法中创建,体现了面形对象的封装性,客户程序不需要知道产品产生的细节,也体现了面向对象的单一职责原则(SRP),这样在产品很少的情况下使用起来还是很方便, 但是如果产品很多,并且不断的有...

收录时间: 2018-07-25
分类: 设计模式
贡献者: Rector
1728 热度

设计模式(十八)—— 中介者模式

模式简介用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显示地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。通常情况下,应用程序由许多类组成,随着类数量不断增加,系统变得难以维护,主要体现在类之间的交互变得更加复杂,难以理解,修改其中一个类可能会影响到其他的类,导致整个系统崩溃。想象机场控制塔控制飞机起飞降落的过程,飞机降落前先与机场控制塔通信,控制塔通知其它飞机...

收录时间: 2018-07-11
分类: 设计模式
贡献者: Rector
1677 热度

单件模式(C#)

单件模式保证一个类只有唯一一个实例,并提供一个全局访问点。《设计模式——可复用面向对象软件的基础》中是这样定义的: 类自身保存了该类的实例对象(自己创建实例),通过截取创建新实例的请求保证没有其他新实例被创建(保证实例唯一),并且提供一个全局访问该实例对象的方法(对外提供唯一访问点),这就是Singleton模式。 常用的场景如:系统日志记录器,系统配置管理器,模态窗口等等。 单件模式也允许子类继承,目前未接触到实际应用,暂无具体了解,所以下面的介绍均不考虑 子类扩展的情况。

收录时间: 2018-07-10
分类: 设计模式
贡献者: Rector
AD 友情赞助