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?
A principle is an abstraction, a guide to design. A pattern is an implementation that solves a particular problem.
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.
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.
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:
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.
I think the answer from @ArslanAli is worth summarizing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With