Introduction
This article is about the principles which we use in the everyday life of a software engineer. This article starts with an introduction of important software design principles. We will also discuss the definitions of various design patterns. In the end, the article discusses how to effectively use design principles while developing/working on software.
What are Software design principles?
Software design principles are a set of guidelines that help developers to make a good system design. They will help you to create a clean and modular design, which will be easy to test, debug, and maintain in the future.
List of Design Principles
I have jotted down important object-oriented design principles and putting them here for quick reference. These will at least give you some idea about what they are and what benefits they offer.
I have tried to arrange the list according to two rules. Firstly, simple to difficult and secondly, the order of importance (although they are all important).
- DRY principle
- YAGNI principle
- KISS principle
- SOLID Principle
There are more principles than these, but we will start with these four.
Definitions
Every principle has the abbreviations, explanations, and detail associated. Let's go through the definitions of each one listed above.
DRY Principle - DON’T REPEAT YOURSELF
This principle guides us to reduce repetition in the code. Reducing repeated code also reduces the necessity to replicate changes applied to a code that was reused in many places of your logic without a proper abstraction to centralize its use and avoid repetition.
YAGINI Principle - YOU AREN’T GONNA NEED IT
Do not add any functionality in your code until it becomes really necessary to have it there. This principle guides us to avoid including functionalities in your code that you think will be necessary for the future but has no use in the present.
KISS Principle - KEEP IT SIMPLE STUPID
Keep the code simple and easily understandable. This principle guides us to write code that is easy to read and maintain. Some tips to accomplish this are:
- Keep the methods small (fewer than 40 lines).
- Give meaningful names to your methods and variables.
- Don’t abuse comments, make the code understandable without the need to comment on everything.
- Make methods to solve small parts.
SOLID Principle
Solid is a set of file principles intended to make software designs more flexible and maintainable. It helps to build software with more cohesive code and less coupling. Each letter of the acronym corresponds to a principle:
- S - Single Responsibility Principle: A class should have only a single responsibility, only one reason to change. (high cohesion, low coupling)
- O - Open/Close Principle: Entities should be open for extension, but closed for modification.
- L - Liskov Substitution Principle: Objects should be replaceable with instances of their subtypes without altering the correctness of the program, otherwise you may be using the wrong abstraction.
- I - Interface Segregation Principle: Avoid one general-purpose interface by creating more specific interfaces.
- D - Dependency Inversion Principle: Depend upon abstractions, not concretions. (reduce coupling)
Summary
In this article, I discussed the main software design patterns, their abbreviations, introduction and a brief discussion about the usage. Going further, in the next part we will discuss each one of them individually with more details and examples.