实施SOLID原则的模式 [英] Patterns to implement SOLID principles

查看:112
本文介绍了实施SOLID原则的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个SOLID设计原则的演示,我正在努力将单一责任原则和开放原则与设计模式联系起来。

I'm doing a presentation of SOLID design principles and I'm trying to connect the Single Responsibility Principle and the Open-Closed principle to design patterns.

目前我有


  • SRP:代理,外观

  • OCP:策略,命令

  • SRP: proxy, façade
  • OCP: strategy, command

是否还有其他基本模式?

Are there any other basic patterns I should include?

推荐答案

SOLID原则比其他任何东西都是更好的OO语言和框架的属性。他们不会轻易地转化为设计模式。相反,它们在设计模式中影响好与坏。

The SOLID principles are more attributes of a good OO language and framework than anything else. They don't handily translate into design patterns. Rather, they influence good vs. bad in a design pattern.

通常,SOLID原理的全部显示在每个设计模式中。如果所有SOLID原则都没有显示出来,那么您可以改进设计模式。

Generally, all of the SOLID principles show up in each design pattern somewhere. If all the SOLID principles don't show up, you have a way to improve on the design pattern.

单一责任是真正的封装加上继承和多态的一些方面。单一责任更多的是如何将问题分解为协作对象并定义这些对象的类的基本原则或原则。所有设计模式都应该说明这一点。

Single Responsibility is really Encapsulation plus some aspects of inheritance and polymorphism. Single Responsibility is more of a basic principle or tenet of how to decompose a problem into cooperating objects and define the classes of those objects. All design patterns should illustrate this.

同样,Open / Closed是一种通常通过继承实现的语言功能。但是它可以通过monkeypatching来完成。所有设计模式都应该说明这一点。

Similarly, Open/Closed is a language feature, usually implemented via inheritance. But it can be done via monkeypatching. All design patterns should illustrate this.

Liskov替换通常是一种语言功能。我们经常用精心设计的多态类实现这一点。有些人认为鸭型打破这个原则,另外一些人说鸭子打字表现出来。有许多依赖Liskov替代的设计模式。具有多态性的任何内容都将展示Liskov替换。

Liskov Substitution, also, is usually a language feature. We often implement this with well-design polymorphic classes. Some folks argue that duck-typing breaks this principle, other say that duck-typing manifests it. There are numerous design patterns which rely on Liskov Substitution. Anything with polymorphism will exhibit Liskov Substitution.

界面隔离可以是一种语言功能。 Java有它。大多数帐户的Python - 不这样做。但是,您会注意到,许多Python项目尝试使用超类和单元测试来形式化其接口定义。

Interface Segregation can be a language feature. Java has it. Python -- by most accounts -- doesn't do this. However, you'll note that many Python projects try to formalize their interface definitions with superclasses and unit tests.

依赖性反转(依赖于抽象)通常是一种语言功能。没有多少设计模式坚持这个。然而,我们中许多人喜欢在Java Collections库中使用抽象,以便我们可以在具体类中使用Liskov替换。

Dependency Inversion (depend on abstractions) is often a language feature. Not many design patterns insist on this. However, many of us like to use the abstractions in the Java Collections library so that we can use Liskov Substitution among the concrete classes.

这篇关于实施SOLID原则的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆