Skip to content

Instantly share code, notes, and snippets.

@boubkhaled
Created December 18, 2022 08:17
Show Gist options
  • Select an option

  • Save boubkhaled/f772bbc6b08781851c20b7e62b4ae614 to your computer and use it in GitHub Desktop.

Select an option

Save boubkhaled/f772bbc6b08781851c20b7e62b4ae614 to your computer and use it in GitHub Desktop.
SOLID-Principles

image

  1. ๐—ฆ๐—ถ๐—ป๐—ด๐—น๐—ฒ ๐—ฅ๐—ฒ๐˜€๐—ฝ๐—ผ๐—ป๐˜€๐—ถ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜† ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐—ฆ๐—ฅ๐—ฃ) - A class should have only one reason to change. This means that a class should have a single, well-defined responsibility and that responsibility should be entirely encapsulated by the class.

  2. ๐—ข๐—ฝ๐—ฒ๐—ป/๐—–๐—น๐—ผ๐˜€๐—ฒ๐—ฑ ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐—ข๐—–๐—ฃ) - Software entities (classes, functions, etc.) should be open for extension but closed for modification. This means that you should be able to add new functionality to a class without changing its existing code, but you should not need to modify the class itself to do so.

  3. ๐—Ÿ๐—ถ๐˜€๐—ธ๐—ผ๐˜ƒ ๐—ฆ๐˜‚๐—ฏ๐˜€๐˜๐—ถ๐˜๐˜‚๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐—Ÿ๐—ฆ๐—ฃ) - Subtypes must be substitutable for their base types. In other words, if a class is derived from another class, you should be able to use the derived class in the same way as the base class without any issues.

  4. ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ณ๐—ฎ๐—ฐ๐—ฒ ๐—ฆ๐—ฒ๐—ด๐—ฟ๐—ฒ๐—ด๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐—œ๐—ฆ๐—ฃ) - Clients should not be forced to depend on interfaces they do not use. This means that you should design your interfaces to be as specific and focused as possible.

  5. ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐˜ƒ๐—ฒ๐—ฟ๐˜€๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐——๐—œ๐—ฃ) - High-level modules should not depend on low-level modules. Both should depend on abstractions. This means that you should design your software so that high-level modules depend on abstractions rather than concrete implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment