0% found this document useful (0 votes)
22 views8 pages

SOLID Principles - Part 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

SOLID Principles - Part 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SOLID Principles

Software Engineering:
Advanced Programming
Lecture 4

Laksith Liyanage
Technical Lead Engineer - Software Engineering
[BSc 1st class (Hons) Information Technology UK, BTEC HND Computer Science UK, BTEC HND Software Development UK]
What is it like to go back to your code after 2 years?

When code comes Legacy, What if your code is having:

Less Readability:

• Hard to understand what a class/ method does


• Need to re-read the code multiple times to get to the part you need to change.
• Need to spend a lot of time to fix a minor bug
• Hence you spend more time reading than writing code
• That will decrease the reliability of the code
• Sometimes fixing one bug will lead to introduce bunch of bugs!

Less Extensibility:

• In dynamic environment changes are occurring frequently!


• So new features may have to introduced.
• If your code is not extensible then constantly adding new features will reduce the reliability and the stability of the
system!

6/26/2023 Laksith Liyanage


SOLID
Robert Cecil Martin

Born: 1952
Nickname: "Uncle Bob" Martin
Known for: Agile Manifesto/ SOLID principles

6/26/2023 Laksith Liyanage


The Legend
Design Patterns
SOLID
SOLID Principles Leads to develop very coherent / readable/
maintainable and upgradable software solutions
OOP

6/26/2023 Laksith Liyanage


SOLID
A class should have Only One Reason to CHANGE!
Avoid multiple responsibilities.
▪ Easy to modify
▪ Easy debugging
▪ Easy to test
▪ Enhance reusability
▪ Less chance for new bugs
EPF & Tax calculations can be taken into separate ▪ Enhance the module reliability
modules(Either into separate functions or classes)

Can write in a separate class

This can be achieved by:


- Increasing High Cohesion while Decreasing the coupling level
6/26/2023 Laksith Liyanage
SOLID – Single Responsibility Principle
A Class/Module should be Open for Extension But Close for Modifications!!
The class/ method should be able to extend its behavior without modifying it!

Whenever new shape comes in this method must change,


which could affect to all the references of this class!

1. Identify the changes that are frequent.


2. Keep the identified areas (which has frequent changes) open for extension.
3. Keep the solid areas (which may not have future alterations) close for modification

- Module should provide extension points to alter its behavior.


- Source code of that module remains unchanged!
6/26/2023 Laksith Liyanage
SOLID – Open/ Closed Principle
Subtypes must be Substitutable for their base types!!
Use inheritance only when the Super Class is replaceable by the Sub Class

This doesn’t have an engine.


Hence wrong inheritance

▪ LSP discourages you to use inheritance


in wrong way
▪ This will ensure the OCP as well

Adhering to LSP will,


- reduce unexpected application crashes!
6/26/2023 Laksith Liyanage
SOLID – Liskov Substitution Principle
Subtypes must be Substitutable for their base types!!

extends

extends
extends

6/26/2023
SOLID – Liskov Substitution Principle Continued..
Laksith Liyanage

You might also like