设计模式和设计原则之间有什么区别? [英] What's the difference between design patterns and design principles?

查看:336
本文介绍了设计模式和设计原则之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ruby on Rails的新手,并且阅读了这些文章.

I'm new to Ruby on Rails, and I went through these articles.

  • Design Patterns in Ruby: Observer, Singleton
  • Design Patterns in Ruby

但是我无法理解设计模式设计原则之间的实际区别. 有人可以解释一下区别吗?

But I couldn't understand the actual difference between design patterns and design principles. Could someone please explain the distinction?

推荐答案

设计原则:

设计原则是我们在设计软件时应遵循的核心抽象原则.请记住,它们不是具体的,而是抽象的.只要我们在允许的条件内,它们便可以以任何语言,在任何平台上应用,而不论状态如何.

Design Principles:

Design principles are core abstract principles which we are supposed to follow while designing software. Remember they aren't concrete - rather abstract. They can be applied on any language, on any platform regardless of the state as long as we are within the permissible conditions.

示例:

  • 封装变化的内容.
  • 用于接口的程序,而不是用于实现的程序.
  • 取决于抽象.不要依赖具体的类.

它们是不断出现的现实世界问题的解决方案,因此,我们无需重新发明轮子,而是遵循经过充分验证,被他人测试并且可以安全遵循的设计模式.现在,设计模式是特定的.仅在条款和条件中可以应用设计模式.

They are solutions to real world problems that pop up time and again, so instead of reinventing the wheel, we follow the design patterns that are well-proven, tested by others, and safe to follow. Now, design patterns are specific; there are terms and conditions only in which a design pattern can be applied.

示例:

  • 单一模式(一个类一次只能有一个实例)

  • Singleton Pattern ( One class can only have one instance at a time )

适配器模式(不同类的匹配接口)

Adapter Pattern ( Match interface of different classes )

以下类比可以帮助您更好地理解差异:

The following analogy will help you understand the difference better:

原理:我们应该教别人,以教育自己和他人,并总体上使我们的国家成为进步的国家.

Principle: We should teach others in order to educate ourselves as well as others, and overall make our nation a progressive nation.

模式:在我们的国家/地区,每位医学毕业生都应该在一个遥远的村庄里教6个月才能完成学位.

Pattern: In our country, each medical doctor graduate is supposed to teach 6 months in a far-away village to complete his/her degree.

这篇关于设计模式和设计原则之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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