Top Banner
SOLIDify your code Arnaud Bellizzi
68

SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Aug 22, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLIDify your codeArnaud Bellizzi

Page 2: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

About me@Oodrive (since 2013)

Team Backup & Archive

Architect

Page 3: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLID● Robert C. Martin - Agile Software Development (2003)

● 5 Principles - S. O. L. I. D.

● Object Oriented design

● About Software Maintainability

Page 4: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Rubber Duck Debugging

Page 5: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLID PrinciplesSingle Responsibility “One class - One reason to change”

Page 6: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLID PrinciplesSingle Responsibility

Open/Closed

“One class - One reason to change”

“Open for extension, Closed for modification”

Page 7: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLID PrinciplesSingle Responsibility

Open/Closed

Liskov Substitution

“One class - One reason to change”

“Open for extension, Closed for modification”

“Subtyping should not break anything”

Page 8: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLID PrinciplesSingle Responsibility

Open/Closed

Liskov Substitution

Interface Segregation

“One class - One reason to change”

“Open for extension, Closed for modification”

“Subtyping should not break anything”

“Use small cohesive interfaces”

Page 9: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

SOLID PrinciplesSingle Responsibility

Open/Closed

Liskov Substitution

Interface Segregation

Dependency Inversion

“One class - One reason to change”

“Open for extension, Closed for modification”

“Subtyping should not break anything”

“Use small cohesive interfaces”

Page 10: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Wait, I lied

Page 11: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Wait, I lied

SOLI Dify your code

Page 12: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependency Inversion Principle

1. High-level modules should not depend on low-level modules.

Page 13: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependency Inversion Principle

1. High-level modules should not depend on low-level modules. Both should depend on abstractions.

Page 14: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependency Inversion Principle

1. High-level modules should not depend on low-level modules. Both should depend on abstractions.

2. Abstractions should not depend on details.

Page 15: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependency Inversion Principle

1. High-level modules should not depend on low-level modules. Both should depend on abstractions.

2. Abstractions should not depend on details.Details should depend on abstractions.

Page 16: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies

A B

Page 17: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies

A B

doBThing()

Page 18: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies

A BCalls

doBThing()

Page 19: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies

A BCalls

doBThing()b.doBThing()

Page 20: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies

A BCalls

Imports

b.doBThing() doBThing()

Page 21: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

doBThing()doBetter()

b.doBThing()

Page 22: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

b.doBThing()b.doBetter()

doBThing()doBetter()

Page 23: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

Changes in B imply changes in A

Page 24: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

Changes in B imply changes in A

External API Business

Page 25: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

Changes in B imply changes in A

External API Business

Page 26: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

Changes in B imply changes in A

Business Persistence

Page 27: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies + Change

A BCalls

Imports

Changes in B imply changes in A

PersistenceBusiness

Page 28: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

DependenciesThere is a problem when . . .

Page 29: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

DependenciesThere is a problem when . . .

B changes often

Page 30: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

DependenciesThere is a problem when . . .

B changes often

We want to Reuse A

Page 31: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependency Inversion Principle

1. High-level modules should not depend on low-level modules. Both should depend on abstractions.

2. Abstractions should not depend on details.Details should depend on abstractions.

Page 32: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ

Page 33: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ I

store(...)

Page 34: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ IImports

store(...)i.store(...)

Page 35: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ PERIImports Implements

store(...)i.store(...)

Page 36: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ PERIImports Implements

i.store(...) store(...) store(...)

Page 37: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ PERIImports Implements

i.store(...) store(...)

Injection

store(...)

Page 38: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ PERIImports Implements

i.store(...) store(...)

ScansInjection

store(...)

Page 39: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ PERIImports Implements

i.store(...) store(...)

InjectionInjects

store(...)

Page 40: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted

BIZ PERIImports Implements

i.store(...) store(...)

Injection

Calls

store(...)

Page 41: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted + Change

BIZ PERIImports Implements

i.store(...) store(...) store(...)

Changes in PER are restricted by Contract

Page 42: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted + Change

BIZ PERIImports Implements

i.store(...) store(...) store(...)

Changes in Contract affect BIZ & PER

Page 43: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted + Change

BIZ PERIOwns Implements

i.store(...) store(...) store(...)

BIZ owns the Contract

Page 44: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted + Change

BIZ PERIOwns Implements

i.store(...) store(...) store(...)

Changes in PER are unseen by BIZ

Page 45: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Dependencies Inverted + Change

BIZ PERIOwns Implements

i.store(...) store(...) store(...)

Changes in PER are unseen by BIZ

Page 46: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Costs

- Requires more code

Page 47: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Costs

- Requires more code

- Performance overhead

Page 48: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Costs

- Requires more code

- Performance overhead

- Where is my implementation ?

Page 49: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Gains

- Protect valuable code from unnecessary change

Page 50: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Gains

- Protect valuable code from unnecessary change

- Increased readability of valuable code

Page 51: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Gains

- Protect valuable code from unnecessary change

- Increased readability of valuable code

Your domain , your rules

Page 52: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Evaluating our modules

Code inspection

Page 53: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Code inspectionEvaluating our modules Explain their responsibilities

Page 54: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Code inspectionEvaluating our modules Explain their responsibilities

Page 55: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Code inspectionEvaluating our modules Explain their responsibilities

Business knows details about

- Persistence- Messaging

Page 56: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Invert all the things

Page 57: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

But Agile wins

- Don’t code for tomorrow

- Don’t plan for reuse

- Refactor towards perfection

Page 58: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

But Agile wins

- Don’t code for tomorrow

- Don’t plan for reuse

- Refactor towards perfection

So where do we start ?

Page 59: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on new code ?

+ Manageable refactors

Page 60: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on new code ?

+ Manageable refactors (as in no refactor)

Page 61: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on new code ?

+ Manageable refactors (as in no refactor)

- Possibly useless

Page 62: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on new code ?

+ Manageable refactors (as in no refactor)

- Possibly useless

- Probably useless

Page 63: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on required changes

+ Probably valuable

Page 64: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on required changes

+ Probably valuable ( at least it changed once )

Page 65: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on required changes

+ Probably valuable ( at least it changed once )

- Keep refactors manageable

Page 66: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Start on required changes

+ Probably valuable ( at least it changed once )

- Keep refactors manageable

↳ 1 use case at a time

Page 67: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Day to day

- Code Review : Look for details

- Pitch abstractions to outsiders

Page 68: SOLIDify your code - Oodrive · 2019. 5. 29. · SOLID Robert C. Martin - Agile Software Development (2003) 5 Principles - S. O. L. I. D. Object Oriented design About Software Maintainability

Thank you