Slide 1

Slide 1 text

4 Key Principles to Craft High-Quality Code Thiago Bomfim

Slide 2

Slide 2 text

Table of contents The Dependency Inversion Principle The Single Responsibility Principle Don’t Repeat Yourself Keep It Simple, Stupid 01 02 04 03 SRP DRY DIP KISS

Slide 3

Slide 3 text

SRP The Single Responsibility Principle 01

Slide 4

Slide 4 text

— Robert C. Martin “Gather together those things that change for the same reason, and separate those things that change for different reasons. ”

Slide 5

Slide 5 text

The Single Responsibility Principle How can you apply SRP? ● Keep your classes and methods small. ● Be careful with many dependencies, look at your imports.

Slide 6

Slide 6 text

The Single Responsibility Principle How can you identify if you are not applying the SRP? ● If you need to change many files to include or change a behavior. ● If you need to change the same file for more than one reason.

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

DRY Don’t Repeat Yourself 02

Slide 9

Slide 9 text

— Robert C. Martin - Clean Code “This is one of the most important rules in this book, and you should take it very seriously. ”

Slide 10

Slide 10 text

Don’t Repeat Yourself How can you apply DRY? ● Avoid duplication. ● Any time you see duplication in the code, it could probably become a subroutine or maybe another class outright.

Slide 11

Slide 11 text

Don’t Repeat Yourself How can you identify if you are not applying the DRY? ● If you are doing Ctrl+C/Ctrl+V and nothing changes. ● If you need to resolve the same problem twice in different places.

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

DIP The Dependency Inversion Principle 03

Slide 14

Slide 14 text

— Robert C. Martin “Depend in the direction of abstraction. High level modules should not depend upon low level details. ”

Slide 15

Slide 15 text

The Dependency Inversion Principle How can you apply DIP? ● Use abstraction to separate the layers. ● Don’t depend on the implementation, depend on the abstractions.

Slide 16

Slide 16 text

The Dependency Inversion Principle How can you identify if you are not applying the DIP? ● If you need to change your core application, or your domain because some API you consume changes, you are probably violating the DRY. ● Can you change the API you consume to another vendor? If you can’t, maybe you are violation the DRY.

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

KISS Keep It Simple, Stupid 04

Slide 20

Slide 20 text

— Leonardo da Vinci “Simplicity is the ultimate sophistication. ”

Slide 21

Slide 21 text

— Antoine de Saint-Exupery “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. ”

Slide 22

Slide 22 text

Keep It Simple, Stupid How can you apply KISS? ● Avoid complex architectures and design solutions to solve simple problems. ● Simplicity should be a key design goal, and complicated complexity should be avoided.

Slide 23

Slide 23 text

Keep It Simple, Stupid How can you identify if you are not applying the KISS? ● How easy is your solution to be understood and extended? ● Are you doing premature optimization?

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

REFERENCES Keep Learning 05

Slide 27

Slide 27 text

Clean Code A Handbook of Agile Software Craftsmanship - Robert Cecil Martin.

Slide 28

Slide 28 text

The Pragmatic Programmer - Andy Hunt, Dave Thomas

Slide 29

Slide 29 text

Test-Driven Java Development - Viktor Farcic, Alex Garcia

Slide 30

Slide 30 text

CREDITS: This presentation template was created by Slidesgo, and includes icons by Flaticon, and infographics & images by Freepik Thanks! Do you have any questions? @ThiagoBfim