Software design principles to revise

Table of contents

No heading

No headings in the article.

  1. Single Responsibility - Each class functionality in your software should be applicable to objects that are associated with that class. Ex. - Order, shopping cart, etc.

  2. Open/Closed - Classes should not modify the source code i.e. whenever possible use the interface to allow classes for an extension, not for modification. Ex. - Payment gateways like stripe, Paytm, etc.

  3. Liskov Substitution - Don't substitute similar classes together assuming things will not change in the future. Create abstractions even for similar classes. Ex. - Square and rectangle possess similarity as the square is a rectangle also but vice versa are not possible.

  4. Interface segregation - Don't put unnecessary stuff in the interface that affects different modules or classes to initialize stuff that they will never use. Ex. - Parking lot interface with payment. The free parking lot class doesn't need to have a payment service.

  5. Dependency inversion - This principle is similar to open/closed but the main diff is its primary mechanism to achieve the open/closed principle. Simplicity, always try to decouple classes as much as possible. Ex. Remote should work with different brands' batteries.