设计模式和设计原则有什么区别? [英] What's the difference between design patterns and design principles?
问题描述
我是 Ruby on Rails 的新手,我浏览了这些文章.
I'm new to Ruby on Rails, and I went through these articles.
但我无法理解设计模式和设计原则之间的实际区别.有人可以解释一下区别吗?
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 that we are supposed to follow while designing software. Remember they aren't concrete - rather abstract. They can be applied in 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屋!