Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between design patterns and design principles?

Tags:

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?

like image 436
Bibek Sharma Avatar asked Jul 09 '15 12:07

Bibek Sharma


People also ask

What is the difference between pattern and principle?

A principle is an abstraction, a guide to design. A pattern is an implementation that solves a particular problem.

What are Design Patterns and SOLID principles?

SOLID is a popular set of design principles that are used in object-oriented software development. SOLID is an acronym that stands for five key design principles: single responsibility principle, open-closed principle, Liskov substitution principle, interface segregation principle, and dependency inversion principle.

What is pattern design principles?

Pattern is the repeating of an object or symbol all over the work of art. Repetition works with pattern to make the work of art seem active. The repetition of elements of design creates unity within the work of art.


2 Answers

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.

like image 151
Arslan Ali Avatar answered Sep 23 '22 03:09

Arslan Ali


I think the answer from @ArslanAli is worth summarizing.

  • Principles apply to all of programming. You should have a very good reason any time you choose not to follow principles.
  • Patterns apply to specific, common problems. You should have a very good reason any time you choose to implement a pattern.
like image 20
jaco0646 Avatar answered Sep 22 '22 03:09

jaco0646