Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

ruby on rails - What's the difference between design patterns and design principles?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Examples:

  • Encapsulate what varies.
  • Program to interfaces, not to implementations.
  • Depend upon abstractions. Do not depend upon concrete classes.

Design Patterns:

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.

Examples:

  • 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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...