SOLID Principles
Building reusable, maintainable, scalable and testable
software.
!1
Who Am I ?
• I’m a passionate software developer, always striving for
excellence.

• I’m a self-taught person, who doesn't fear to learn from
my mistakes.

• I’m part of the Domain Team DevOps as a software
developer.

!2
Motivation
	 When we are designing a software or a some of its
pieces, we wish some behaviours as result.
• Reusable.
• Scalable.
• Testable.
• Specially maintainable.
!3
OOP Fundamentals
• Cohesion
• Coupling
• Encapsulation
• Polymorphism
!4
Cohesion
	 "The action or fact of forming a united whole." -
Oxford Dictionaries.
	 "(of objects) the state of sticking together, or (of
people) being in close agreement and working well
together” - Dictionary Cambridge.
!5
Coupling
	 "A device for connecting parts of machinery.” - Oxford
Dictionaries.
	 "A device that joins two things together.” - Dictionary
Cambridge.
	 Strong coupling, where the dependency between the
parts are complex, making hard to change or customize,
turning the process expensive.
!6
Coupling
	 "A device for connecting parts of machinery.” - Oxford
Dictionaries.
	 "A device that joins two things together.” - Dictionary
Cambridge.
	 Strong coupling, where the dependency between the
parts are complex, making hard to change or customize,
turning the process expensive.
	 Weak coupling is the opposite, where we have pieces
or modules easy to change and with the minimal impact
as possible.
!7
Encapsulation
	 "The action of enclosing something in or as if in a
capsule.” - Oxford Dictionaries.
"A good approach in a class design, is to hide its
structures and exposes only its operations." - Robert C.
Martin
!8
Polymorphism
	 "The condition of occurring in several different forms.”
- Oxford Dictionaries.
	 "A feature of a programming language that allows
routines to use variables of different types at different
times.” - Dictionary Cambridge.
!9
Ok, What about SOLID ?
• SOLID, actually is a acronym for a set of good
practices.
• Robert C.Martin(Uncle Bob).
• Agile Software Development, Principles, Patterns, and
Practices
!10
Ok, What about SOLID ?
	 Oh, answering the question, all this knowledge is
based on OOP fundamentals that we saw before.
This acronym bring to us five(5) principles:
• Single Responsibility Principle(SRP).
• Open/Closed Principle(OCP).
• Liskov Substitution Principle(LSP).
• Interface Segregation Principle(ISP).
• Dependency inversion Principle(DIP).
!11
Following these principles, Am I writing clean
code ?
!12
	 Humn… Actually, Not yet, However, these principles
will guide you through the Clean Code way of life.
To write a clean code, we have to follow others rules, like
the ones below and many others:
• Choose descriptive and unambiguous names.
• Make meaningful distinction.
• Use pronounceable names.
• Use searchable names.
• Replace magic numbers with named constants.
Single Responsibility Principle
	 “A class should have only one reason to change.”
	 “Each responsibility is an axis of change.” - Robert
C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 8.
	 “The opportunity or ability to act independently and
take decisions without authorization.” - Oxford
Dictionaries.
Let's look some code!
!13
Open/Closed Principle
	 “Software entities should be open for extension but
closed for modification.”
	 “If OCP is applied well, further changes of that kind are
achieved by adding new code, not by changing old code
that already works.” - Robert C.Martin, Agile Principles, Patterns and
Practices in C#, Chapter 9.
• Strategy pattern.
• Template method.
Let's look some code, again..
!14
Liskov Substitution Principle
	 “Subtypes must be substitutable for their base types.” -
Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 10.
	
	 “Let Φ(x) be a property provable about objects x of
type T. Then Φ(y) should be true for objects y of type S
where S is a subtype of T.” - Barbara Liskov, keynote “Data
abstraction”, 1987.
I know… you’re waiting for it :)
!15
Interface Segregation Principle
	 “Clients should not be forced to depend on methods
they do not use.” - Robert C.Martin, Agile Principles, Patterns and
Practices in C#, Chapter 12.
!16
Dependency-Inversion Principle
	 “High-level modules should not depend on low-level
modules. Both should depend on abstractions.”
	 “Abstractions should not depend upon details. Details
should depend upon abstractions.”
- Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 11.
!17
Conclusion!
!18
Questions ?
!19
Thank you!
!20
Icaro.ferreira@softplan.com.br

SOLID Principles, Building reusable, maintainable, scalable and testable software.

  • 1.
    SOLID Principles Building reusable,maintainable, scalable and testable software. !1
  • 2.
    Who Am I? • I’m a passionate software developer, always striving for excellence. • I’m a self-taught person, who doesn't fear to learn from my mistakes. • I’m part of the Domain Team DevOps as a software developer. !2
  • 3.
    Motivation When weare designing a software or a some of its pieces, we wish some behaviours as result. • Reusable. • Scalable. • Testable. • Specially maintainable. !3
  • 4.
    OOP Fundamentals • Cohesion •Coupling • Encapsulation • Polymorphism !4
  • 5.
    Cohesion "The actionor fact of forming a united whole." - Oxford Dictionaries. "(of objects) the state of sticking together, or (of people) being in close agreement and working well together” - Dictionary Cambridge. !5
  • 6.
    Coupling "A devicefor connecting parts of machinery.” - Oxford Dictionaries. "A device that joins two things together.” - Dictionary Cambridge. Strong coupling, where the dependency between the parts are complex, making hard to change or customize, turning the process expensive. !6
  • 7.
    Coupling "A devicefor connecting parts of machinery.” - Oxford Dictionaries. "A device that joins two things together.” - Dictionary Cambridge. Strong coupling, where the dependency between the parts are complex, making hard to change or customize, turning the process expensive. Weak coupling is the opposite, where we have pieces or modules easy to change and with the minimal impact as possible. !7
  • 8.
    Encapsulation "The actionof enclosing something in or as if in a capsule.” - Oxford Dictionaries. "A good approach in a class design, is to hide its structures and exposes only its operations." - Robert C. Martin !8
  • 9.
    Polymorphism "The conditionof occurring in several different forms.” - Oxford Dictionaries. "A feature of a programming language that allows routines to use variables of different types at different times.” - Dictionary Cambridge. !9
  • 10.
    Ok, What aboutSOLID ? • SOLID, actually is a acronym for a set of good practices. • Robert C.Martin(Uncle Bob). • Agile Software Development, Principles, Patterns, and Practices !10
  • 11.
    Ok, What aboutSOLID ? Oh, answering the question, all this knowledge is based on OOP fundamentals that we saw before. This acronym bring to us five(5) principles: • Single Responsibility Principle(SRP). • Open/Closed Principle(OCP). • Liskov Substitution Principle(LSP). • Interface Segregation Principle(ISP). • Dependency inversion Principle(DIP). !11
  • 12.
    Following these principles,Am I writing clean code ? !12 Humn… Actually, Not yet, However, these principles will guide you through the Clean Code way of life. To write a clean code, we have to follow others rules, like the ones below and many others: • Choose descriptive and unambiguous names. • Make meaningful distinction. • Use pronounceable names. • Use searchable names. • Replace magic numbers with named constants.
  • 13.
    Single Responsibility Principle “A class should have only one reason to change.” “Each responsibility is an axis of change.” - Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 8. “The opportunity or ability to act independently and take decisions without authorization.” - Oxford Dictionaries. Let's look some code! !13
  • 14.
    Open/Closed Principle “Softwareentities should be open for extension but closed for modification.” “If OCP is applied well, further changes of that kind are achieved by adding new code, not by changing old code that already works.” - Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 9. • Strategy pattern. • Template method. Let's look some code, again.. !14
  • 15.
    Liskov Substitution Principle “Subtypes must be substitutable for their base types.” - Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 10. “Let Φ(x) be a property provable about objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T.” - Barbara Liskov, keynote “Data abstraction”, 1987. I know… you’re waiting for it :) !15
  • 16.
    Interface Segregation Principle “Clients should not be forced to depend on methods they do not use.” - Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 12. !16
  • 17.
    Dependency-Inversion Principle “High-levelmodules should not depend on low-level modules. Both should depend on abstractions.” “Abstractions should not depend upon details. Details should depend upon abstractions.” - Robert C.Martin, Agile Principles, Patterns and Practices in C#, Chapter 11. !17
  • 18.
  • 19.
  • 20.