Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Write S.O.L.I.D code

Write S.O.L.I.D code

Learn how to write Object Oriented S.O.L.I.D code

Yoan

June 13, 2017
Tweet

More Decks by Yoan

Other Decks in How-to & DIY

Transcript

  1. @yot88
    By yoan thirion
    S.O.L.I.D principles

    View Slide

  2. @yot88
    bad code / Good code
    Bad code vs Good code
    Categorize each piece of code

    View Slide

  3. View Slide

  4. @yot88
    Singleton
    Tight Coupling
    Untestability
    Premature Optimization
    Indescriptive Naming
    Duplication
    Single Responsibility
    Open/Closed Principle
    Liskov Substitution
    Interface Segregation
    Dependency Inversion
    Patterns and anti-patterns

    View Slide

  5. @yot88
    SRP
    A class should have only 1 responsibility

    View Slide

  6. @yot88
    Software entities should be open for extension,
    but closed for modification.
    Open closed

    View Slide

  7. @yot88
    Subtypes must be substitutable for their base types.
    Liskov substitution

    View Slide

  8. @yot88
    Clients should not be forced to depend on methods
    that they do not use.
    Interface segregation

    View Slide

  9. @yot88
    High level modules should not depend on low level modules :
    both should depend on abstractions.
    DI

    View Slide

  10. @yot88
    Good code / bad code
    Align each piece of code with a S.O.L.I.D principle

    View Slide

  11. 1
    3 3
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  12. 3 13
    16
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  13. 3 4
    2
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  14. 3 15
    14
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  15. 3 8
    6
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  16. 3 11
    9
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  17. 3 10
    5
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  18. 12
    1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  19. 1 3
    16 13
    2 4
    14
    15
    6
    8
    9 12 5 10 11

    View Slide

  20. @yot88
    Let’s refactor using s.O.L.I.D

    View Slide

  21. @yot88
    exercises
    Practice S.O.L.I.D principles on code examples
    Clone the repository at : https://github.com/ythirion/solid-kata
    Foreach code example :
    • identify why it’s breaking the given principle
    • Write down your refactoring strategy
    • Refactor it

    View Slide

  22. @yot88
    Where do you stand ?
    No quite yet
    On the way
    Ready to roll

    View Slide