0%

Design Patterns and Principles of Object-Oriented design

What are design patterns

Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general probloms that software developer faced during software development.

As Design pattern - Elements of reusable Object-Oriented Software, there are 23 design patterns which can be classified in three categories: Creational, Structural and Behavioral patterns.

Principles of object-oriented design(SOLID)

S.O.L.I.D is an acronym for the first five object-oriented design(OOD) principles by Robert C. Martin, popularly known as Uncle Bob.

These principles, when combined together, make it easy for a programmer to develop software that are easy to maintain and extend.

  1. Single-responsibility Principle(S.R.P for short – this principle states that: A class should have one and only one reason to change, meaning that a class should have only one job.
  2. Open-closed Principle: Objects or entities should be open for extension, but closed for modification. This simply means that a class should be easily extendable without modifying the class itself.
  3. Liskov substitution principle: if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of that program (correctness, task performed, etc.).
  4. Interface segregation principle: Clients should not be forced to implement interfaces they don’t use. Many client specific interfaces are better than one general purpose interface.
  5. Dependency Inversion principle: Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.

Orther principles

  • Program to Interface Not Implementation.
  • Don’t Repeat Yourself.
  • Encapsulate What Varies.
  • Depend on Abstractions, Not Concrete
  • classes. Least Knowledge Principle.
  • Favor Composition over
  • Inheritance. Hollywood Principle.
  • Apply Design Pattern wherever possible.
  • Strive for Loosely Coupled System.
  • Keep it Simple and Sweet / Stupid.

References

Liskov substitution principle
Object Oriented Design Principles
Design Pattern - Overview