Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

@ktrajchevska

Slide 4

Slide 4 text

@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.

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

@ktrajchevska

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

@ktrajchevska

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

@ktrajchevska

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

@ktrajchevska

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

@ktrajchevska

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

App\ZohoCandidate.php

Slide 18

Slide 18 text

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.

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

App\Http\Controllers\CandidateController.php

Slide 21

Slide 21 text

@ktrajchevska Changing storage from CRM to MySQL

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

@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.

Slide 28

Slide 28 text

@ktrajchevska Time to switch: 30 days

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

@ktrajchevska 1. Segregate the interfaces.

Slide 31

Slide 31 text

@ktrajchevska App\Repositories\Interfaces\CandidateRepositoryInterface.php

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

@ktrajchevska App\Repositories\ZohoCandidateRepository.php

Slide 34

Slide 34 text

@ktrajchevska App\Http\Controllers\CandidateController.php

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

@ktrajchevska App\Crm\Candidate.php

Slide 37

Slide 37 text

@ktrajchevska profile.blade.php

Slide 38

Slide 38 text

@ktrajchevska 4. Separate the responsibilities.

Slide 39

Slide 39 text

@ktrajchevska

Slide 40

Slide 40 text

@ktrajchevska 5. Close the code for modification.

Slide 41

Slide 41 text

@ktrajchevska App\Providers\AppServiceProvider.php

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

@ktrajchevska

Slide 44

Slide 44 text

@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.

Slide 45

Slide 45 text

@ktrajchevska Time to switch: 5 days

Slide 46

Slide 46 text

@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.

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

@ktrajchevska ⚠ “Refactor away from SRP”

Slide 49

Slide 49 text

@ktrajchevska

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

@ktrajchevska Thank you!