Design Principles

Agenda

This article will cover below things:

1) What are software design principles?

2) Why software design principles important?

3) Various design principles & their details.


1) What are software design principles?

Software design principles are a set of guidelines that helps developers to make a good system design.

Basically, Software design is only a part of the development process in the design step (please look at the below image about development process).
Before we do software design (low-level)  we have to complete software architecture (high-level).
Choosing an architecture will determine how to deal with performance, fault tolerance, scalability, and reliability.
Software design is responsible for code level(low-level) such as, what each module is doing, class scope, methods purposes, and so on.



2) Why software design principles important?

“Without good software design, programming is an art of adding bugs to an empty text file” -Louise Srygley

I have seen a trend where most of developers tend to jump to code directly, which is quite obvious that is what we've been taught. This happened with me also, during my initial projects, I have always jumped to code directly, and I never realized the importance of designing because all those were small and developed by myself only. So I didn't run into any issue while changing the software or maintaining it. But when I started working on large scale projects which required many developers to work together and it had a very complex implementation then I began to realize the importance of "Software Design".

We have many solutions to apply Software Design Principles to your project. You can think and apply your solution or use the Design Patterns. The design pattern is the best solution to resolve common problems that repeat many times in software development. Using the design pattern will reduce risks and make your code easy to maintain.

Besides, if you want to contribute to open-source which often uses a lot of Design Patterns: Singleton, Factory Method, Decorator Pattern, Strategy Pattern, Proxy, and so on. I think you have to understand those patterns then you can contribute to it. Moreover, if you want to create a framework like Lavarel Framework(Taylor Otwell),I think you should deeply understand the Software Design Principles and Design Patterns. Learning Design Pattern isn’t difficult, you can search on the internet or watch them on youtube but identify and apply them in the real project is very difficult. You can achieve it after working with many projects in many years.


3) Various design principles & their details.


i) SOLID principle.

A) Single responsibility principle
    "A class should have one and only one reason to change, meaning that a class should have only one job".

    "just because you can, doesn't mean you should."

B) Open/closed principle
    "Objects or entities should be open for extension but closed for modification".

    for example, If you have to wear a coat/jacket, you don't have to open your chest/body.

C) Liskov's substitution principle
    "Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program".
    
    for example, if it looks like a duck and quacks like a duck but needs batteries, you probably have the wrong abstraction.

    This principle states that objects of a parent’s class should be replaceable with objects of the child’s class without breaking the logic of the application. That requires the objects of your child’s class to behave in the same way as the objects of your parent’s class.

D) Interface segregation principle
    “Many client-specific interfaces are better than one general-purpose interface.”

    Like the Single Responsibility Principle(SRP), the target of the Interface Segregation Principle is to reduce the side effects and frequency of required changes by splitting the code into multiple/independent parts.

E) 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."

    for example, Would you solder a lamp directly to the electric wiring in a wall? No right, instead you will plug it into switch board and do your work. The point here is, abstraction is important, like plug and play.

    another real life example would be of TV remote battery. Your remote needs a battery but it's not dependent on the battery brand. You can use any XYZ brand and it will work. So we can say that the TV remote is loosely coupled with the brand name.

ii)DRY principle (Don't repeat yourself)

    This principle states that each small pieces of knowledge (code) may only occur exactly once in the entire system.

iii) KISS principle (Keep it simple, stupid!)

    This principle states that try to keep each small piece of software simple and unnecessary complexity could be avoided.

iv) YAGNI principle (You ain't gonna need it)

    This principle states that always implement things when you actually need them never implement things before you need them.

Comments

Popular posts from this blog

KMP Algorithm: Pattern Searching in Text

Z-Function Algorithm: Substring Search

Back of the envelope estimations