03- SW Design - SOLID Principles - part1
03- SW Design - SOLID Principles - part1
▪ Design principles
▪ SOLID principles
▪ Open-Closed Principle
▪ Summary
▪ You can use these points to check whether you are writing bad, dirty code or not :
▪ Does the code implement a design pattern?
▪ Imagine a scenario in which you’re writing a program of math software and you
need to implement all possible math operations.
▪ You’ll need to make changes in both modules whenever you are required to
make changes to either module.
▪ This means your application or software is tightly coupled, which means your
code qualifies as dirty code
▪ Helps us to improve code quality and draw our focus to the main purpose of
our task.
▪ It makes sure that new changes are tested and will not break any existing
code functionality
▪ Note: Visit your code and see if you can read it. If not, that means
you are writing bad code.
▪ It’s possible that you are doing the same things in many places
▪ Developers write lots of code that would be better split into pieces like
small functions or properties.
▪ Especially for new developers who did not actually write that code.
▪ has-a (composition)
▪ Is-a (inheritance).
▪ The DatabaseClient is a heavy duty class with all helper methods required to
access the DB.
▪ Not when they assume that something might be useful in the future.
▪ The development team should focus only on the current iteration to deliver
the agreed scope in time.
▪ Because in the end, it usually turns out that you don’t need it, or that
what you need is different from what you expected.
▪ You don’t have to find ways to use suboptimal solutions that you had
already developed before you had the full picture.
▪ Open-Closed Principle.
▪ SOLID principles are simply guidelines for making our code and
programming robust.
19-Feb-24 60
Single Responsibility Principle
▪ A class should have only one reason to change.
▪ Deposit
▪ Send OTP
▪ Now bank provide info for Personal Loan, Home Loan and car loan.
▪ People may want to provide some other loan feature like study loan then again
you need to modify this class.
▪ sendOTP() method
▪ People may want to introduced send OTP as Phone then again you need to
change its implementation.
19-Feb-24 75
Open-Closed Principle(OCP)
▪ A software artifact should be open for extension but closed for
modification.
19-Feb-24 89
Liskov substitution Principle(LSP)
▪ Derived or child classes must be substitutable for their base or
parent classes.
▪ Design principles
▪ SOLID principles
▪ Open-Closed Principle