SlideShare a Scribd company logo
The OO Design PrinciplesThe OO Design Principles
Agenda
Need of Design
Design Smells
2
Class Design Principles
Summary
Agenda
Need of Design
Design Smells
3
Class Design Principles
Summary
What's meaning
of design..?
What's the different
compared to
Design is
about how
What Design Exactly About is..?
4
compared to
analysis..?
Analysis is
about what
Why do we
Need
Design..?
To deliver
faster
To manage
change
Why do we need design..?
5
change
To deal with
complexity
Agenda
Need of Design
Design Smells
6
Class Design Principles
Summary
Okay... I under stand the
Importance of design
How do we know a
Design is bad..?
Design Smells
7
Are they any symptoms
Of bad design...
Immobility
Viscosity
Rigidity
Fragility
Design Smells(contd…)
8
ViscosityFragility
Rigidity
Tendency for software to be difficult to change.
The design is hard to change
9
Tendency for software to be difficult to change.
Single change causes cascade of subsequent changes in
dependent modules.
The more module must be changed the more rigid the
design.
Fragility
Tendency of the software to break in many places every
The design is easy to break
10
Tendency of the software to break in many places every
time it's changed .
The breakage occurs in areas with no conceptual
relationship
On every fix the software breaks in unexpected way.
Immobility
Inability to reuse software from other projects or modules .
Difficult to reuse
11
Inability to reuse software from other projects or modules .
The useful module have to many dependencies.
Cost of rewriting is less compared to the risk faced to
separate those part.
Viscosity
It's easy to do the wrong thing, but hard to do the right
Hard to do the right thing
12
It's easy to do the wrong thing, but hard to do the right
thing.
When the design preserving methods are more difficult to
use then the hacks
When dev environment is slow and inefficient developer
will be tempted to do wrong things.
Why design becomes rigid,
Fragile Immobile and viscousIs there any
Characteristics
For good design
Design Characteristics
13
High cohesion
Improper
dependencies
Between modules
Design Characteristics
14
Low coupling
So how can we
Achieve good
Design..?
SRP
LSP
OCP
Design Characteristics
15
ISP
DIP
So let's go SOLID..
Single Responsibility Principle
There should never be more then one reason
This is hard to see, as we think
Responsibility in group
16
There should never be more then one reason
to change a class.
Many responsibility means many reason to
change.
1. Removes the immobility Smell from
Design.
2. Deodorizes the Rigidity Smell
Ohh.. SRP
Benefits of SRP
17
Open Closed Principle
Software entities should be open for extension, but closed for
Abstraction is the key
18
Software entities should be open for extension, but closed for
modification.
Keep the things that change frequently away from things that
don't change.
Open Closed Principle (contd…)
Open for Extension
Behavior of the module
can be extended.
Closed for Modification
The source of such a module
is invisible.
OCP is the heart of object oriented design
19
Make the module behave
in new and different ways
as the requirement of the
application change.
Resist making source change
to it.
Is 100%
Closer
possible
Is there any
techniques
In Reality 100% Closer
is not attainable.
Closer must be
Strategic.
Abstraction is the key
Further thinking of OCP
20
Flexibility, re usability
and maintainability is
The benefits
Liskov's SubstitutionPrinciple
LSP defines the inheritance principle.
Subclass should be substitutable for their base class
21
LSP defines the inheritance principle.
It makes clear that in OO design IS-A relationship is about
behavior; behavior that clients depend on.
If client uses a base class, then it should not differentiate
the base class.
LSP Violation Example
void g(Rectangle r)
{
r.setWidth(5);
r.setHeight(4);
if(r.getArea() != 20)
throw new
Exception("Bad area!");
Square is not
Rectangle!
22
Exception("Bad area!");
}
IS-A Relationship
Square’s behavior is
changed, so it is not
substitutable to
Rectangle
Further thinking of LSP
In order to be substitutable, the contract of the base class
must be honored by the derived class.
Derived class substitutable or base class, if
Design by Contract
23
Derived class substitutable or base class, if
Preconditions are no stronger then the base class
Preconditions are no weaker then the base class
Derived method should expect no more and provide no less
LSP Violation
The solution will likely to be put into an if else statement in the
client side.
Are you sure it works?
What happen if new
derivatives of rectangle
come..?
May be we've allocate
24
May be we've allocate
The responsibility
Wrongly.
It violates OCP
Interface Segregation Principle
Client should not forced to depend on methods they do not
Many client specific interface are Better then one
general purpose interface
25
Client should not forced to depend on methods they do not
use.
ISP deals with designing cohesive interfaces and avoiding
fat interfaces.
What happen when the big class changes? All depending
module must also change.
Service
<<Client A methods>>
+ ...
<<Client B methods>>
+ ...
<<Client C methods>>
+ ...
Client A
Client B
An violation of ISP example
26
ISP violation
Client C
Segregated
interface
Service
<<Interface>>
Service A
<<Client A methods>>
+ ..
<<Interface>>
Service B
Client A
An violation of ISP example: Solution
27
<<Client A methods>>
+ ...
<<Client B methods>>
+ ...
<<Client C methods>>
+ ...
Service B
<<Client B methods>>
+ ..
<<Interface>>
Service C
<<Client C methods>>
+ ..
Client B
Client C
Dependency Inversion Principle
High level module should not depend upon low level
Depend upon abstraction. Do not depend
Upon concretions
28
High level module should not depend upon low level
modules, both should depends upon abstraction
Abstraction should not depends upon on details, details
should depends on abstraction.
DIP
A DIP example
29
DIP
violation
DIP Summary
Inversion of dependencies is the hallmark of good object
oriented design.
If it's dependencies are inverted, it has an OO design If it's
dependencies are not inverted it has a procedural design.
Dependency injection is the core of the famous spring
30
Dependency injection is the core of the famous spring
framework
Hollywood principle: “ Don't call us, we'll call you”.
Summary
• A class should have only one reason to changeSRP
• A Module should be open for extension but
closed for modification.OCP
• Subclass should be substitutable for their base
LSP
31
• Subclass should be substitutable for their base
class.LSP
• Many client specific interfaces are better then
one general purpose interface .ISP
• Depends upon abstraction. Do not depends
upon concretions.DIP
Questions ???Questions ???
Solid Principle

More Related Content

PPTX
Solid Principles
PPTX
Learning solid principles using c#
PDF
Introduction to SOLID Principles
PDF
Solid Principles
PPTX
Clean code: SOLID
PPTX
S.O.L.I.D. Principles for Software Architects
PDF
Object Oriented Design Principles
PPTX
Solid principles
Solid Principles
Learning solid principles using c#
Introduction to SOLID Principles
Solid Principles
Clean code: SOLID
S.O.L.I.D. Principles for Software Architects
Object Oriented Design Principles
Solid principles

What's hot (20)

KEY
SOLID Design Principles
PPT
principles of object oriented class design
PPTX
SOLID principles
PPTX
Clean code
PPT
SOLID Design Principles
PPTX
[부스트캠프 웹・모바일 7기 Tech Talk]이지훈_뉴비의 시점에서 바라본 Kotlin_suspend
KEY
Solid principles
PDF
SOLID Design Principles applied in Java
PPTX
Solid Principles
PPTX
SOLID _Principles.pptx
PPTX
SOLID, DRY, SLAP design principles
PPTX
ドメイン駆動開発 勉強会 ①
PDF
SOLID Principle & Design Pattern.pdf
PPTX
Design principles - SOLID
PPTX
Solid design principles
PPTX
Single Responsibility Principle
PPTX
Clean code: SOLID (iOS)
PDF
Ruby on Rails for beginners
PPTX
Solid principles
SOLID Design Principles
principles of object oriented class design
SOLID principles
Clean code
SOLID Design Principles
[부스트캠프 웹・모바일 7기 Tech Talk]이지훈_뉴비의 시점에서 바라본 Kotlin_suspend
Solid principles
SOLID Design Principles applied in Java
Solid Principles
SOLID _Principles.pptx
SOLID, DRY, SLAP design principles
ドメイン駆動開発 勉強会 ①
SOLID Principle & Design Pattern.pdf
Design principles - SOLID
Solid design principles
Single Responsibility Principle
Clean code: SOLID (iOS)
Ruby on Rails for beginners
Solid principles
Ad

Similar to Solid Principle (20)

PDF
Object-oriented design principles
PPTX
OO Design Principles
PPT
DesignPrinciples-and-DesignPatterns
PPT
SOLID principles-Present
PPTX
Improving Software Quality Using Object Oriented Design Principles
PDF
Inversion of Control
PPTX
Object Oriented Design SOLID Principles
PPTX
TEST PPT
ODP
Geecon09: SOLID Design Principles
PPT
Object Oriented Concepts and Principles
PDF
Understanding SOLID Principles in OOP programming
KEY
"SOLID" Object Oriented Design Principles
PPTX
SOLID Principles
PPT
The OO Design Principles
PDF
Solid principle
PPTX
L07 Design Principles
PPTX
SOLID Principles
PPTX
1012892161-Module-4-Agile-Software-Design-and-Development.pptx
PPTX
SOLID Principles in OOPS ooooooooo.pptx
PPTX
Birth of a developer
Object-oriented design principles
OO Design Principles
DesignPrinciples-and-DesignPatterns
SOLID principles-Present
Improving Software Quality Using Object Oriented Design Principles
Inversion of Control
Object Oriented Design SOLID Principles
TEST PPT
Geecon09: SOLID Design Principles
Object Oriented Concepts and Principles
Understanding SOLID Principles in OOP programming
"SOLID" Object Oriented Design Principles
SOLID Principles
The OO Design Principles
Solid principle
L07 Design Principles
SOLID Principles
1012892161-Module-4-Agile-Software-Design-and-Development.pptx
SOLID Principles in OOPS ooooooooo.pptx
Birth of a developer
Ad

Recently uploaded (20)

PPTX
rapid fire quiz in your house is your india.pptx
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PDF
SEVA- Fashion designing-Presentation.pdf
PPTX
An introduction to AI in research and reference management
PDF
Chalkpiece Annual Report from 2019 To 2025
PDF
Urban Design Final Project-Site Analysis
PPTX
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PDF
Phone away, tabs closed: No multitasking
DOCX
A Contemporary Luxury Villa in Dubai Jumeirah-2.docx
PPTX
HPE Aruba-master-icon-library_052722.pptx
PPT
robotS AND ROBOTICSOF HUMANS AND MACHINES
PPTX
Special finishes, classification and types, explanation
PPTX
AD Bungalow Case studies Sem 2.pptxvwewev
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PPTX
Media And Information Literacy for Grade 12
PDF
Quality Control Management for RMG, Level- 4, Certificate
rapid fire quiz in your house is your india.pptx
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
SEVA- Fashion designing-Presentation.pdf
An introduction to AI in research and reference management
Chalkpiece Annual Report from 2019 To 2025
Urban Design Final Project-Site Analysis
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
Phone away, tabs closed: No multitasking
A Contemporary Luxury Villa in Dubai Jumeirah-2.docx
HPE Aruba-master-icon-library_052722.pptx
robotS AND ROBOTICSOF HUMANS AND MACHINES
Special finishes, classification and types, explanation
AD Bungalow Case studies Sem 2.pptxvwewev
DOC-20250430-WA0014._20250714_235747_0000.pptx
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
Media And Information Literacy for Grade 12
Quality Control Management for RMG, Level- 4, Certificate

Solid Principle

  • 1. The OO Design PrinciplesThe OO Design Principles
  • 2. Agenda Need of Design Design Smells 2 Class Design Principles Summary
  • 3. Agenda Need of Design Design Smells 3 Class Design Principles Summary
  • 4. What's meaning of design..? What's the different compared to Design is about how What Design Exactly About is..? 4 compared to analysis..? Analysis is about what
  • 5. Why do we Need Design..? To deliver faster To manage change Why do we need design..? 5 change To deal with complexity
  • 6. Agenda Need of Design Design Smells 6 Class Design Principles Summary
  • 7. Okay... I under stand the Importance of design How do we know a Design is bad..? Design Smells 7 Are they any symptoms Of bad design...
  • 9. Rigidity Tendency for software to be difficult to change. The design is hard to change 9 Tendency for software to be difficult to change. Single change causes cascade of subsequent changes in dependent modules. The more module must be changed the more rigid the design.
  • 10. Fragility Tendency of the software to break in many places every The design is easy to break 10 Tendency of the software to break in many places every time it's changed . The breakage occurs in areas with no conceptual relationship On every fix the software breaks in unexpected way.
  • 11. Immobility Inability to reuse software from other projects or modules . Difficult to reuse 11 Inability to reuse software from other projects or modules . The useful module have to many dependencies. Cost of rewriting is less compared to the risk faced to separate those part.
  • 12. Viscosity It's easy to do the wrong thing, but hard to do the right Hard to do the right thing 12 It's easy to do the wrong thing, but hard to do the right thing. When the design preserving methods are more difficult to use then the hacks When dev environment is slow and inefficient developer will be tempted to do wrong things.
  • 13. Why design becomes rigid, Fragile Immobile and viscousIs there any Characteristics For good design Design Characteristics 13
  • 15. So how can we Achieve good Design..? SRP LSP OCP Design Characteristics 15 ISP DIP So let's go SOLID..
  • 16. Single Responsibility Principle There should never be more then one reason This is hard to see, as we think Responsibility in group 16 There should never be more then one reason to change a class. Many responsibility means many reason to change.
  • 17. 1. Removes the immobility Smell from Design. 2. Deodorizes the Rigidity Smell Ohh.. SRP Benefits of SRP 17
  • 18. Open Closed Principle Software entities should be open for extension, but closed for Abstraction is the key 18 Software entities should be open for extension, but closed for modification. Keep the things that change frequently away from things that don't change.
  • 19. Open Closed Principle (contd…) Open for Extension Behavior of the module can be extended. Closed for Modification The source of such a module is invisible. OCP is the heart of object oriented design 19 Make the module behave in new and different ways as the requirement of the application change. Resist making source change to it.
  • 20. Is 100% Closer possible Is there any techniques In Reality 100% Closer is not attainable. Closer must be Strategic. Abstraction is the key Further thinking of OCP 20 Flexibility, re usability and maintainability is The benefits
  • 21. Liskov's SubstitutionPrinciple LSP defines the inheritance principle. Subclass should be substitutable for their base class 21 LSP defines the inheritance principle. It makes clear that in OO design IS-A relationship is about behavior; behavior that clients depend on. If client uses a base class, then it should not differentiate the base class.
  • 22. LSP Violation Example void g(Rectangle r) { r.setWidth(5); r.setHeight(4); if(r.getArea() != 20) throw new Exception("Bad area!"); Square is not Rectangle! 22 Exception("Bad area!"); } IS-A Relationship Square’s behavior is changed, so it is not substitutable to Rectangle
  • 23. Further thinking of LSP In order to be substitutable, the contract of the base class must be honored by the derived class. Derived class substitutable or base class, if Design by Contract 23 Derived class substitutable or base class, if Preconditions are no stronger then the base class Preconditions are no weaker then the base class Derived method should expect no more and provide no less
  • 24. LSP Violation The solution will likely to be put into an if else statement in the client side. Are you sure it works? What happen if new derivatives of rectangle come..? May be we've allocate 24 May be we've allocate The responsibility Wrongly. It violates OCP
  • 25. Interface Segregation Principle Client should not forced to depend on methods they do not Many client specific interface are Better then one general purpose interface 25 Client should not forced to depend on methods they do not use. ISP deals with designing cohesive interfaces and avoiding fat interfaces. What happen when the big class changes? All depending module must also change.
  • 26. Service <<Client A methods>> + ... <<Client B methods>> + ... <<Client C methods>> + ... Client A Client B An violation of ISP example 26 ISP violation Client C
  • 27. Segregated interface Service <<Interface>> Service A <<Client A methods>> + .. <<Interface>> Service B Client A An violation of ISP example: Solution 27 <<Client A methods>> + ... <<Client B methods>> + ... <<Client C methods>> + ... Service B <<Client B methods>> + .. <<Interface>> Service C <<Client C methods>> + .. Client B Client C
  • 28. Dependency Inversion Principle High level module should not depend upon low level Depend upon abstraction. Do not depend Upon concretions 28 High level module should not depend upon low level modules, both should depends upon abstraction Abstraction should not depends upon on details, details should depends on abstraction.
  • 30. DIP Summary Inversion of dependencies is the hallmark of good object oriented design. If it's dependencies are inverted, it has an OO design If it's dependencies are not inverted it has a procedural design. Dependency injection is the core of the famous spring 30 Dependency injection is the core of the famous spring framework Hollywood principle: “ Don't call us, we'll call you”.
  • 31. Summary • A class should have only one reason to changeSRP • A Module should be open for extension but closed for modification.OCP • Subclass should be substitutable for their base LSP 31 • Subclass should be substitutable for their base class.LSP • Many client specific interfaces are better then one general purpose interface .ISP • Depends upon abstraction. Do not depends upon concretions.DIP