What is the difference between Design Patterns and Design Principles?

Andrew

Administrator
Staff member
Messages
26
Likes
6
Trophy Points
5
Followers
2
Joined
Mar 17, 2022

Design Patterns​

Design Patterns are techniques for how to design and architect your code. They are low-level solutions related to the implementation to real-world problems that arise again and again, so instead of inventing the wheel, we follow design patterns that are well-proven, tested by others, and safe to follow. Design Patterns offer a specific implementation for a specific object-oriented programming problem. Each design pattern has a different use case and applies to a different scenario.

Examples of Design Patterns:
  • Active Record Pattern (A database table or view is wrapped into a class)
  • Singleton Pattern (One class can only have one instance at a time)

Design Principles​

Design Principles are the best practices and core abstract (high-level) principles to ensure scalable software architecture and mastery. In most cases, you need to follow them to have quality code. For example, the Single Responsibility Principle (SRP) suggests that a class should have only one reason to change. This is a high-level statement that we should keep in mind while designing or creating classes for our application. SRP does not provide specific implementation steps and it is up to developers how they implement it in their applications.

Some principles imply some design patterns. For example, the Open/Closed principle closely implies the Strategy pattern. Meanwhile, the Dependency Injection principle has strong ties to the MVC pattern.

Examples of Design Principles:
  • Single Responsibility Principle
  • Open/Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle

TL;DR​

  • Design Patterns are applied to specific common problems. You should have a very good reason every time you decide to implement a pattern.
  • Design Principles are applied to all programming. You should have a very good reason every time you decide not to follow principles.

 
Top