Object Oriented Design Principles

This article is intended for those who at least have basic understading of Object Oriented Programming. Developers who know the difference between a class and an object and can talk about the fundamentals of Object Oriented Programming i.e., Encapsulation, Abstraction, Polymorphism and Inheritance. If you're new to OOP, I highly recommend reading this tutorial, Object Oriented Programming using C#. 
 
Software design can be a heaven or hell. If a software is not designed correctly, it can become a nightmare for developers. If a software is designed properly, it will be a smooth ride for current developers as well as the developers who will work on it in future.
 
Industry experts and architects have come up with some design principles if used property can help software building process a smooth ride. This article talks about some of the commonly used design principles on object oriented programming.
 
Introduction Objects, Objects and Objects!!!
 
What else do we have in Object Oriented Programming. Ya we have classes right? In Object Oriented Programming, we create software systems by treating everything as an object, like customer object, supplier object etc. These objects interact with each other. Object Oriented Design is a part of standard software development best practices where software achitetects with the technical leads start building software design and architecture.
 
Scalability, flexibility, dependability, and extensibility are some of the common functionalities must be kept in mind when designing new software systems. If a software is not extensible, it will be a nightmare to add new functionalities in future. Dependencies in the system One of the biggest reasons for the damage done to software design is the introduction of unplanned dependencies into the system. Every part of the system depends on some other part and so a change in one part will affect another part. If we are able to manage those dependencies then we will easily maintain the software system as well as the software quality. For exmaple, a data access layer can depend on the business layper. A minot change in business layer can break the data layer. 
 
BALDAL.png
 
 
Principles, Design Patterns and Software Architecture
 
Software architecture like MVC, 3-Tier, MVP tells us how the overall software project will be structured.
 
Design pattern lets us reuse the experience, or we can say it provides reusable solutions to commonly occurring problems. Example: the problems of object creation, instance management and many more.
 
Design principles tell us, do these and you will do this, how you will do it, it's up to you. Everyone defines some principles for their life like, I never lie, I never drink and so on. He/she follows these principles to make his/her life easy, but how he/she will comply is up to him/her.
 
In the same way, Object Oriented Design is filled with several principles that let us manage problems of software design.
 
Mr Robert Martin, commonly known as Uncle Bob, introduced some class design principles of which later Michael Feathers gave the acronym SOLID Principles. SOLID principles are one of the commonly used design principles. In SOLD: 
  1. S - SRP - Single responsibility Principle. SRP says "Every software module should have only one reason to change". (Note: Software Module, Class, Function etc. Reason to change Responsibility)
  2. O - OCP -- Open Close Principle. It says "Software modules should be closed for modifications but open for extensions."
  3. L - LSP - Liskov substitution principle. It says "Subclasses should be substitutable for base classes."
  4. I -" ISP- Interface Segregation principle. It states that "Clients should not be forced to implement interfaces they don't use". It can also be stated as "Many client specific interfaces are better than one general purpose interface"
  5. D - DIP-Dependency Inversion principle. It says "High level modules should not depend upon low level modules. Rather, both should depend upon abstractions." 
If you really want to learn SOLD Principles, I highly recommend reading this detailed tutorial: SOLID Principles In C#
 
There are some principles that play important roles in Object Oriented Design but not categorized like SOLID is. They are:
  1. Program to Interface Not Implementation.
  2. Don't Repeat Yourself.
  3. Encapsulate What Varies.
  4. Depend on Abstractions, Not Concrete classes.
  5. Least Knowledge Principle.
  6. Favor Composition over Inheritance.
  7. Hollywood Principle.
  8. Apply Design Pattern wherever possible.
  9. Strive for Loosely Coupled System.
  10. Keep it Simple and Sweet / Stupid. 
Here is a detailed tutorial on DRY Principles, Don't Repeat Yourself Design Principle
 
Conclusion
 
Changes are unavoidable storms in software development, we can only create software designs in such a way that the changes can be adopted, perhaps not completely but at least somewhat.
 
Hope all of you enjoyed reading this article.