$30 off During Our Annual Pro Sale. View Details »

SOLID design principles for better team performance

SOLID design principles for better team performance

A short overview of SOLID design principles with a practical example of how using them can improve team performance and reduce time needed to extend and maintain software.

Katerina Trajchevska

November 10, 2019
Tweet

More Decks by Katerina Trajchevska

Other Decks in Programming

Transcript

  1. SOLID design
    principles for better
    team performance
    Katerina Trajchevska, Bulgaria PHP 2019

    View Slide

  2. @ktrajchevska
    Katerina Trajchevska
    ● Co-founder of Adeva, an
    exclusive developers’ network.
    ● Software Engineer & Mozilla Tech
    Speaker
    ● Consultant with startups and
    Fortune 500
    @ktrajchevska

    View Slide

  3. @ktrajchevska

    View Slide

  4. @ktrajchevska
    SOLID design principles
    ー Write code that’s easy to maintain.
    ー Easily extend the software with new functionality
    without breaking existing ones.
    ー Spend less time reading and more time writing
    code.

    View Slide

  5. @ktrajchevska
    A class should have
    only one reason to
    change.
    Single Responsibility Principle

    View Slide

  6. @ktrajchevska

    View Slide

  7. @ktrajchevska
    A class should be open
    for extension, but
    closed for modification.
    Open/Closed Principle

    View Slide

  8. @ktrajchevska

    View Slide

  9. @ktrajchevska
    Don’t switch
    implementations,
    unless they give the
    same result.
    Liskov Substitution Principle

    View Slide

  10. @ktrajchevska

    View Slide

  11. @ktrajchevska
    Don’t depend on
    methods you don’t use.
    Interface Segregation Principle

    View Slide

  12. @ktrajchevska

    View Slide

  13. @ktrajchevska
    Depend on
    abstractions, not
    concretions.
    Dependency Inversion Principle

    View Slide

  14. @ktrajchevska

    View Slide

  15. @ktrajchevska
    Real Life SOLID
    Implementing developer
    profiles on Adeva’s
    Platform.

    View Slide

  16. View Slide

  17. App\ZohoCandidate.php

    View Slide

  18. App\Http\Controllers\CandidateController.php
    Controller knows too much and is open for modification.
    Methods depend directly on the CRM storage and their naming conventions.

    View Slide

  19. profile.blade.php
    View uses arrays that should be replaced with Collections in future.

    View Slide

  20. App\Http\Controllers\CandidateController.php

    View Slide

  21. @ktrajchevska
    Changing storage
    from CRM to MySQL

    View Slide

  22. @ktrajchevska
    1. Adjust the edit method to work with MySQL

    View Slide

  23. @ktrajchevska
    2. Adjust the view to work with the new implementation

    View Slide

  24. @ktrajchevska
    3. Adjust the update method to work with MySQL

    View Slide

  25. @ktrajchevska
    3. Adjust the update method to work with MySQL (cont’d)

    View Slide

  26. @ktrajchevska
    3. Adjust the update method to work with MySQL (cont’d)

    View Slide

  27. @ktrajchevska
    What does it take to change the storage?
    1. Add Eloquent models to use with MySQL.
    2. Change controller dependencies from CRM class to
    Eloquent.
    3. Use Eloquent instead of CRM to pull data for the view.
    4. Switch all variables to the new naming convention.
    5. Change the way we access data in the views.
    6. Adjust the unit tests to work accordingly.

    View Slide

  28. @ktrajchevska
    Time to switch: 30
    days

    View Slide

  29. @ktrajchevska
    How can we improve
    team performance by
    using SOLID design
    principles?

    View Slide

  30. @ktrajchevska
    1. Segregate the
    interfaces.

    View Slide

  31. @ktrajchevska
    App\Repositories\Interfaces\CandidateRepositoryInterface.php

    View Slide

  32. @ktrajchevska
    2. Don’t depend on
    concrete
    implementations.

    View Slide

  33. @ktrajchevska
    App\Repositories\ZohoCandidateRepository.php

    View Slide

  34. @ktrajchevska
    App\Http\Controllers\CandidateController.php

    View Slide

  35. @ktrajchevska
    3. Be mindful about
    what your program
    expects.

    View Slide

  36. @ktrajchevska
    App\Crm\Candidate.php

    View Slide

  37. @ktrajchevska
    profile.blade.php

    View Slide

  38. @ktrajchevska
    4. Separate the
    responsibilities.

    View Slide

  39. @ktrajchevska

    View Slide

  40. @ktrajchevska
    5. Close the code for
    modification.

    View Slide

  41. @ktrajchevska
    App\Providers\AppServiceProvider.php

    View Slide

  42. @ktrajchevska
    Changing storage
    from CRM to MySQL:
    Take #2

    View Slide

  43. @ktrajchevska

    View Slide

  44. @ktrajchevska
    What does it take to switch the storage?
    1. Add Eloquent models to use with MySQL.
    2. Create MysqlCandidateRepository that implements
    CandidateRepositoryInterface.
    3. Change the binding for
    CandidateRepositoryInterface.

    View Slide

  45. @ktrajchevska
    Time to switch: 5 days

    View Slide

  46. @ktrajchevska
    Better team performance with SOLID
    ー Spending less time reading code.
    ー Reducing time needed to extend the software.
    ー Reducing bugs by closing the core of the system.
    ー Improving productivity and reducing costs.

    View Slide

  47. @ktrajchevska
    Is SOLID a “one size fits
    all” ?

    View Slide

  48. @ktrajchevska
    ⚠ “Refactor away from
    SRP”

    View Slide

  49. @ktrajchevska

    View Slide

  50. @ktrajchevska
    Software Design
    Principles are your
    tools, not your goals.

    View Slide

  51. @ktrajchevska
    Thank you!

    View Slide