SlideShare a Scribd company logo
Copyright © 2019 ONE BCG. All rights reserved.
SOLID Principles
2
Copyright © 2019 ONE BCG. All rights reserved.
• Separation of Concerns
• Extendibility
• Code Usability
• Maintainability
• Testability
Challenges in Applications
3
Copyright © 2019 ONE BCG. All rights reserved.
• Don’t repeat yourself - DRY
• Separation of Concerns
• Don’t make me Think
• Make it Simple
…….. Now question is how to do it...
How to Achieve It?
4
Copyright © 2019 ONE BCG. All rights reserved.
• Architectural Design Representation
• Architectural Design Output
• Architectural Styles
• Data-flow Architecture
• Object-oriented Architecture
• Layered Architecture
• Data-centered Architecture
• Call and Return Architecture
Follow Architectural Design Principles
5
Copyright © 2019 ONE BCG. All rights reserved.
Software design principles represent a set of guidelines that helps us to avoid having a
bad design. The design principles are associated with Robert Martin, who gathered them in
"Agile Software Development: Principles, Patterns, and Practices". According to Robert
Martin there are 3 important characteristics of a bad design that should be avoided:
● Rigidity - It is hard to change because every change affects too many other parts of
the system.
● Fragility - When you make a change, unexpected parts of the system break.
● Immobility - It is hard to reuse in another application because it cannot be
disentangled from the current application.
Design Principles
6
Copyright © 2019 ONE BCG. All rights reserved.
• S - Single Responsibility Principle - SRP
• O - Open/closed principle
• L - Liskov Substitution Principle - LSP
• I - Interface Segregation Principle
• D - Dependency Inversion Principle
SOLID Principle
7
Copyright © 2019 ONE BCG. All rights reserved.
Single Responsibility Principle was introduced by Tom DeMarco in his book Structured
Analysis and Systems Specification, 1979. Robert Martin reinterpreted the concept and
defined the responsibility as a reason to change.
“A class should have only one reason to change”
What does it mean exactly… ??
The SRP is one of the simplest of the SOLID principles but also one of the most difficult to
get right. Collecting and gathering responsibilities to one place is a common thing to do
and happens in a natural way. Finding and separating those responsibilities from one
another is much of what software design is really about.
Single Responsibility Principle
8
Copyright © 2019 ONE BCG. All rights reserved.
This principle states that if we have 2 reasons to change for a class, we have to split the
functionality into two classes. Each class will handle only one responsibility and on the
future if we need to make one change we are going to make it in the class which handles
it. When we need to make a change in a class having more responsibilities the change
might affect the other functionality of the classes.
- A reason to change
A class or method should have only one reason to change.
- Single Responsibility
A class or method should have only a single responsibility.
Single Responsibility Principle
9
Copyright © 2019 ONE BCG. All rights reserved.
Single Responsibility Principle
10
Copyright © 2019 ONE BCG. All rights reserved.
Why Not?
When a class has more than one responsibility, there are also more triggers and reasons to
change that class. Responsibility is the same as “a reason for change” in this context.
Changes to one responsibility may impair or inhibit the class’s ability to meet the others.
This kind of coupling leads to fragile designs that break in unexpected ways when
changed. If a class has more than one responsibility, then the responsibilities become
coupled. Also when a (functional) responsibility is divided over more than one class, all
classes part of that responsibility have to change. They are caught in the chain of change.
Always try to give every class its own and unique responsibility.
Single Responsibility Principle
11
Copyright © 2019 ONE BCG. All rights reserved.
How?
Separating responsibility can be done by defining for every responsibility a class or an
interface. It makes no difference, a class can be seen as nothing more than a container of
code, like a file or a library. What's important is that responsibilities are separated by
abstraction and therefore can be implemented by different consumers of that interface.
Single Responsibility Principle
12
Copyright © 2019 ONE BCG. All rights reserved.
“Software entities like classes, modules, and functions should be open for extension
but closed for modifications.”
OPC is a generic principle. You can consider it when writing your classes to make sure that
when you need to extend their behavior you don’t have to change the class but to extend
it. The same principle can be applied for modules, packages, libraries. If you have a library
containing a set of classes there are many reasons for which you’ll prefer to extend it
without changing the code that was already written (backward compatibility, regression
testing, etc). This is why we have to make sure our modules follow the Open-Closed
Principle.
When referring to the classes Open Close Principle can be ensured by the use of Abstract
Classes and concrete classes for implementing their behavior. This will enforce having
Concrete Classes extending Abstract Classes instead of changing them. Some particular
cases of this are the Template Pattern and Strategy Pattern.
Open Closed Principle
13
Copyright © 2019 ONE BCG. All rights reserved.
How?
The best way to implement the open-closed principle is to first start with implementing the
Single Responsibility Principle: a class should have one, and only one, the reason to
change. This will separate different concerns in your code.
The next step is to represent these separate concerns by abstractions and let consumers
of these concerns talk to these abstractions.
To state the open-closed principle in a very straightforward way, you can say:
Open Closed Principle
14
Copyright © 2019 ONE BCG. All rights reserved.
• You should design modules that never change.
• When requirements change, you extend the behavior of such modules by adding new
code, not by changing old code that already works.
• Abstraction is the way to realize this principle.
• Derivatives from abstraction are closed for modification because the abstraction is
fixed but behavior can be extended by creating new derivatives of the abstraction.
Open Closed Principle
15
Copyright © 2019 ONE BCG. All rights reserved.
Liskov Substitution Principle was introduced by Barbara Liskov in a 1987 Conference on
Object-Oriented Programming Systems Languages and Applications.
Barbara Liskov: “If S is a subtype of T, then objects of type T may be replaced with
objects of type S, without breaking the program.”
In other words...
“Derived types must be completely substitutable for their base types.”
This principle is just an extension of the Open-Closed Principle in terms of behavior
meaning that we must make sure that new derived classes are extending the base classes
without changing their behavior. The new derived classes should be able to replace the
base classes without any change in the code.
Still Confused….
Liskov Substitution Principle
16
Copyright © 2019 ONE BCG. All rights reserved.
The Liskov substitution principle (LSP) is a collection of guidelines for creating inheritance
hierarchies in which a client can reliably use any class or subclass without compromising
the expected behavior. If the rules of the LSP are not followed, an extension to a class
hierarchy—that is, a new subclass—might necessitate changes to any client of the base
class or interface.
If the LSP is followed, clients can remain unaware of changes to the class hierarchy. As
long as there are no changes to the interface, there should be no reason to change any
existing code. The LSP, therefore, helps to enforce both the open/closed principle and the
single responsibility principle.
Liskov Substitution Principle
17
Copyright © 2019 ONE BCG. All rights reserved.
“Clients should not be forced to depend upon
interfaces that they don't use.”
This principle teaches us to take care how we write our
interfaces. When we write our interfaces we should take
care to add only methods that should be there. If we add
methods that should not be there the classes
implementing the interface will have to implement those
methods as well. For example if we create an interface
called Worker and add a method lunch break, all the
workers will have to implement it. What if the worker is a
robot?
Interface Segregation Principle
18
Copyright © 2019 ONE BCG. All rights reserved.
1. “High-level modules should not depend on low-level modules. Both should
depend on abstractions.”
2. “Abstractions should not depend on details. Details should depend on
abstractions.”
Dependency Inversion Principle states that we should decouple high-level modules from
low-level modules, introducing an abstraction layer between the high-level classes and
low-level classes. Furthermore, it inverts the dependency: instead of writing our
abstractions based on details, we should write the details based on abstractions.
Dependency Inversion Principle
19
Copyright © 2019 ONE BCG. All rights reserved.
Dependency Inversion or Inversion of Control is better to know terms referring to how the
dependencies are realized. Classically when a software module(class, framework) needs
some other module, it initializes and holds a direct reference to it. This will make the 2
modules tight coupled. To decouple them the first module will provide a hook(a property,
parameter) and an external module controlling the dependencies will inject the reference
to the second one.
By applying the Dependency Inversion the modules can be easily changed by other
modules just changing the dependency module. Factories and Abstract Factories can be
used as dependency frameworks, but there are specialized frameworks for that, known as
Inversion of Control Container.
Dependency Inversion Principle
20
Copyright © 2019 ONE BCG. All rights reserved.

More Related Content

Similar to An ultimate guide to SOLID Principles, developers must know.

Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
rainynovember12
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
Basavaraj Patil
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of Control
Shuhab Tariq
 
S.O.L.I.D. principles of software development
S.O.L.I.D. principles of software developmentS.O.L.I.D. principles of software development
S.O.L.I.D. principles of software development
AmanSoni129
 
Soild principles
Soild principlesSoild principles
Soild principles
Avidnyat Chiddarwar
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
Faizan Haider
 
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?
Steve Green
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test Automaion
Knoldus Inc.
 
Dependency Injection, Design Principles and Patterns
Dependency Injection, Design Principles and PatternsDependency Injection, Design Principles and Patterns
Dependency Injection, Design Principles and Patterns
Juan Lopez
 
GDSC - SOLID Principles session.pptx
GDSC - SOLID Principles session.pptxGDSC - SOLID Principles session.pptx
GDSC - SOLID Principles session.pptx
AaliyanShaikh
 
Practical Enterprise Application Development
Practical Enterprise Application DevelopmentPractical Enterprise Application Development
Practical Enterprise Application Development
Adil Mughal
 
Solid Principles, for better cohesion and lower coupling
Solid Principles, for better cohesion and lower coupling Solid Principles, for better cohesion and lower coupling
Solid Principles, for better cohesion and lower coupling
Mohammad Shawahneh
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
Mahmoud Asadi
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
Anju Kanjirathingal
 
PMSE pdf
PMSE pdfPMSE pdf
PMSE pdf
ADARSHN40
 
Solid principles
Solid principlesSolid principles
Solid principles
Kumaresh Chandra Baruri
 
The Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary VersionThe Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary Version
Philip Schwarz
 
Solid principle
Solid principleSolid principle
Solid principle
muhammadali0014
 
android principle.pptx
android principle.pptxandroid principle.pptx
android principle.pptx
debasish duarah
 

Similar to An ultimate guide to SOLID Principles, developers must know. (20)

Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
Solid
SolidSolid
Solid
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of Control
 
S.O.L.I.D. principles of software development
S.O.L.I.D. principles of software developmentS.O.L.I.D. principles of software development
S.O.L.I.D. principles of software development
 
Soild principles
Soild principlesSoild principles
Soild principles
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test Automaion
 
Dependency Injection, Design Principles and Patterns
Dependency Injection, Design Principles and PatternsDependency Injection, Design Principles and Patterns
Dependency Injection, Design Principles and Patterns
 
GDSC - SOLID Principles session.pptx
GDSC - SOLID Principles session.pptxGDSC - SOLID Principles session.pptx
GDSC - SOLID Principles session.pptx
 
Practical Enterprise Application Development
Practical Enterprise Application DevelopmentPractical Enterprise Application Development
Practical Enterprise Application Development
 
Solid Principles, for better cohesion and lower coupling
Solid Principles, for better cohesion and lower coupling Solid Principles, for better cohesion and lower coupling
Solid Principles, for better cohesion and lower coupling
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
 
PMSE pdf
PMSE pdfPMSE pdf
PMSE pdf
 
Solid principles
Solid principlesSolid principles
Solid principles
 
The Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary VersionThe Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary Version
 
Solid principle
Solid principleSolid principle
Solid principle
 
android principle.pptx
android principle.pptxandroid principle.pptx
android principle.pptx
 

More from ONE BCG

A comprehensive guide to user behavioral analytics
A comprehensive guide to user behavioral analytics A comprehensive guide to user behavioral analytics
A comprehensive guide to user behavioral analytics
ONE BCG
 
What is product development and its process?
What is product development and its process?What is product development and its process?
What is product development and its process?
ONE BCG
 
Why effective communication with clients is necessary?
Why effective communication with clients is necessary?Why effective communication with clients is necessary?
Why effective communication with clients is necessary?
ONE BCG
 
How Artificial intelligence and machine learning are different?
How Artificial intelligence and machine learning are different? How Artificial intelligence and machine learning are different?
How Artificial intelligence and machine learning are different?
ONE BCG
 
What is Agile and Scrum, their guiding principles and methods?
What is Agile and Scrum, their guiding principles and methods?What is Agile and Scrum, their guiding principles and methods?
What is Agile and Scrum, their guiding principles and methods?
ONE BCG
 
Prototype: Its methods, techniques, and key features.
Prototype: Its methods, techniques, and key features.Prototype: Its methods, techniques, and key features.
Prototype: Its methods, techniques, and key features.
ONE BCG
 
How to prepare a project for automated deployment?
How to prepare a project for automated deployment?How to prepare a project for automated deployment?
How to prepare a project for automated deployment?
ONE BCG
 
What is Load, Stress and Endurance Testing?
What is Load, Stress and Endurance Testing?What is Load, Stress and Endurance Testing?
What is Load, Stress and Endurance Testing?
ONE BCG
 
Software risk analysis and management
Software risk analysis and managementSoftware risk analysis and management
Software risk analysis and management
ONE BCG
 
What is security testing and why it is so important?
What is security testing and why it is so important?What is security testing and why it is so important?
What is security testing and why it is so important?
ONE BCG
 
Brushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developersBrushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developers
ONE BCG
 

More from ONE BCG (11)

A comprehensive guide to user behavioral analytics
A comprehensive guide to user behavioral analytics A comprehensive guide to user behavioral analytics
A comprehensive guide to user behavioral analytics
 
What is product development and its process?
What is product development and its process?What is product development and its process?
What is product development and its process?
 
Why effective communication with clients is necessary?
Why effective communication with clients is necessary?Why effective communication with clients is necessary?
Why effective communication with clients is necessary?
 
How Artificial intelligence and machine learning are different?
How Artificial intelligence and machine learning are different? How Artificial intelligence and machine learning are different?
How Artificial intelligence and machine learning are different?
 
What is Agile and Scrum, their guiding principles and methods?
What is Agile and Scrum, their guiding principles and methods?What is Agile and Scrum, their guiding principles and methods?
What is Agile and Scrum, their guiding principles and methods?
 
Prototype: Its methods, techniques, and key features.
Prototype: Its methods, techniques, and key features.Prototype: Its methods, techniques, and key features.
Prototype: Its methods, techniques, and key features.
 
How to prepare a project for automated deployment?
How to prepare a project for automated deployment?How to prepare a project for automated deployment?
How to prepare a project for automated deployment?
 
What is Load, Stress and Endurance Testing?
What is Load, Stress and Endurance Testing?What is Load, Stress and Endurance Testing?
What is Load, Stress and Endurance Testing?
 
Software risk analysis and management
Software risk analysis and managementSoftware risk analysis and management
Software risk analysis and management
 
What is security testing and why it is so important?
What is security testing and why it is so important?What is security testing and why it is so important?
What is security testing and why it is so important?
 
Brushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developersBrushing skills on SignalR for ASP.NET developers
Brushing skills on SignalR for ASP.NET developers
 

Recently uploaded

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 

Recently uploaded (20)

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 

An ultimate guide to SOLID Principles, developers must know.

  • 1. Copyright © 2019 ONE BCG. All rights reserved. SOLID Principles
  • 2. 2 Copyright © 2019 ONE BCG. All rights reserved. • Separation of Concerns • Extendibility • Code Usability • Maintainability • Testability Challenges in Applications
  • 3. 3 Copyright © 2019 ONE BCG. All rights reserved. • Don’t repeat yourself - DRY • Separation of Concerns • Don’t make me Think • Make it Simple …….. Now question is how to do it... How to Achieve It?
  • 4. 4 Copyright © 2019 ONE BCG. All rights reserved. • Architectural Design Representation • Architectural Design Output • Architectural Styles • Data-flow Architecture • Object-oriented Architecture • Layered Architecture • Data-centered Architecture • Call and Return Architecture Follow Architectural Design Principles
  • 5. 5 Copyright © 2019 ONE BCG. All rights reserved. Software design principles represent a set of guidelines that helps us to avoid having a bad design. The design principles are associated with Robert Martin, who gathered them in "Agile Software Development: Principles, Patterns, and Practices". According to Robert Martin there are 3 important characteristics of a bad design that should be avoided: ● Rigidity - It is hard to change because every change affects too many other parts of the system. ● Fragility - When you make a change, unexpected parts of the system break. ● Immobility - It is hard to reuse in another application because it cannot be disentangled from the current application. Design Principles
  • 6. 6 Copyright © 2019 ONE BCG. All rights reserved. • S - Single Responsibility Principle - SRP • O - Open/closed principle • L - Liskov Substitution Principle - LSP • I - Interface Segregation Principle • D - Dependency Inversion Principle SOLID Principle
  • 7. 7 Copyright © 2019 ONE BCG. All rights reserved. Single Responsibility Principle was introduced by Tom DeMarco in his book Structured Analysis and Systems Specification, 1979. Robert Martin reinterpreted the concept and defined the responsibility as a reason to change. “A class should have only one reason to change” What does it mean exactly… ?? The SRP is one of the simplest of the SOLID principles but also one of the most difficult to get right. Collecting and gathering responsibilities to one place is a common thing to do and happens in a natural way. Finding and separating those responsibilities from one another is much of what software design is really about. Single Responsibility Principle
  • 8. 8 Copyright © 2019 ONE BCG. All rights reserved. This principle states that if we have 2 reasons to change for a class, we have to split the functionality into two classes. Each class will handle only one responsibility and on the future if we need to make one change we are going to make it in the class which handles it. When we need to make a change in a class having more responsibilities the change might affect the other functionality of the classes. - A reason to change A class or method should have only one reason to change. - Single Responsibility A class or method should have only a single responsibility. Single Responsibility Principle
  • 9. 9 Copyright © 2019 ONE BCG. All rights reserved. Single Responsibility Principle
  • 10. 10 Copyright © 2019 ONE BCG. All rights reserved. Why Not? When a class has more than one responsibility, there are also more triggers and reasons to change that class. Responsibility is the same as “a reason for change” in this context. Changes to one responsibility may impair or inhibit the class’s ability to meet the others. This kind of coupling leads to fragile designs that break in unexpected ways when changed. If a class has more than one responsibility, then the responsibilities become coupled. Also when a (functional) responsibility is divided over more than one class, all classes part of that responsibility have to change. They are caught in the chain of change. Always try to give every class its own and unique responsibility. Single Responsibility Principle
  • 11. 11 Copyright © 2019 ONE BCG. All rights reserved. How? Separating responsibility can be done by defining for every responsibility a class or an interface. It makes no difference, a class can be seen as nothing more than a container of code, like a file or a library. What's important is that responsibilities are separated by abstraction and therefore can be implemented by different consumers of that interface. Single Responsibility Principle
  • 12. 12 Copyright © 2019 ONE BCG. All rights reserved. “Software entities like classes, modules, and functions should be open for extension but closed for modifications.” OPC is a generic principle. You can consider it when writing your classes to make sure that when you need to extend their behavior you don’t have to change the class but to extend it. The same principle can be applied for modules, packages, libraries. If you have a library containing a set of classes there are many reasons for which you’ll prefer to extend it without changing the code that was already written (backward compatibility, regression testing, etc). This is why we have to make sure our modules follow the Open-Closed Principle. When referring to the classes Open Close Principle can be ensured by the use of Abstract Classes and concrete classes for implementing their behavior. This will enforce having Concrete Classes extending Abstract Classes instead of changing them. Some particular cases of this are the Template Pattern and Strategy Pattern. Open Closed Principle
  • 13. 13 Copyright © 2019 ONE BCG. All rights reserved. How? The best way to implement the open-closed principle is to first start with implementing the Single Responsibility Principle: a class should have one, and only one, the reason to change. This will separate different concerns in your code. The next step is to represent these separate concerns by abstractions and let consumers of these concerns talk to these abstractions. To state the open-closed principle in a very straightforward way, you can say: Open Closed Principle
  • 14. 14 Copyright © 2019 ONE BCG. All rights reserved. • You should design modules that never change. • When requirements change, you extend the behavior of such modules by adding new code, not by changing old code that already works. • Abstraction is the way to realize this principle. • Derivatives from abstraction are closed for modification because the abstraction is fixed but behavior can be extended by creating new derivatives of the abstraction. Open Closed Principle
  • 15. 15 Copyright © 2019 ONE BCG. All rights reserved. Liskov Substitution Principle was introduced by Barbara Liskov in a 1987 Conference on Object-Oriented Programming Systems Languages and Applications. Barbara Liskov: “If S is a subtype of T, then objects of type T may be replaced with objects of type S, without breaking the program.” In other words... “Derived types must be completely substitutable for their base types.” This principle is just an extension of the Open-Closed Principle in terms of behavior meaning that we must make sure that new derived classes are extending the base classes without changing their behavior. The new derived classes should be able to replace the base classes without any change in the code. Still Confused…. Liskov Substitution Principle
  • 16. 16 Copyright © 2019 ONE BCG. All rights reserved. The Liskov substitution principle (LSP) is a collection of guidelines for creating inheritance hierarchies in which a client can reliably use any class or subclass without compromising the expected behavior. If the rules of the LSP are not followed, an extension to a class hierarchy—that is, a new subclass—might necessitate changes to any client of the base class or interface. If the LSP is followed, clients can remain unaware of changes to the class hierarchy. As long as there are no changes to the interface, there should be no reason to change any existing code. The LSP, therefore, helps to enforce both the open/closed principle and the single responsibility principle. Liskov Substitution Principle
  • 17. 17 Copyright © 2019 ONE BCG. All rights reserved. “Clients should not be forced to depend upon interfaces that they don't use.” This principle teaches us to take care how we write our interfaces. When we write our interfaces we should take care to add only methods that should be there. If we add methods that should not be there the classes implementing the interface will have to implement those methods as well. For example if we create an interface called Worker and add a method lunch break, all the workers will have to implement it. What if the worker is a robot? Interface Segregation Principle
  • 18. 18 Copyright © 2019 ONE BCG. All rights reserved. 1. “High-level modules should not depend on low-level modules. Both should depend on abstractions.” 2. “Abstractions should not depend on details. Details should depend on abstractions.” Dependency Inversion Principle states that we should decouple high-level modules from low-level modules, introducing an abstraction layer between the high-level classes and low-level classes. Furthermore, it inverts the dependency: instead of writing our abstractions based on details, we should write the details based on abstractions. Dependency Inversion Principle
  • 19. 19 Copyright © 2019 ONE BCG. All rights reserved. Dependency Inversion or Inversion of Control is better to know terms referring to how the dependencies are realized. Classically when a software module(class, framework) needs some other module, it initializes and holds a direct reference to it. This will make the 2 modules tight coupled. To decouple them the first module will provide a hook(a property, parameter) and an external module controlling the dependencies will inject the reference to the second one. By applying the Dependency Inversion the modules can be easily changed by other modules just changing the dependency module. Factories and Abstract Factories can be used as dependency frameworks, but there are specialized frameworks for that, known as Inversion of Control Container. Dependency Inversion Principle
  • 20. 20 Copyright © 2019 ONE BCG. All rights reserved.