Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Clean Code - quick summary ● Naming ● Small functions ● Meaningful comments ● Data abstraction ● Error Handling ● TDD(Unit Tests) ● Building Systems

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Goals At working at module level, software structure should ● Tolerate changes ● Easy to understand ● Basic components for reuse

Slide 5

Slide 5 text

Our Enemies ● Rigidity - difficult to change ● Fragility - easy to break ● Immobility - difficult to reuse ● Viscosity - resistance against making changes

Slide 6

Slide 6 text

SOLID Principles ● Single Responsibility ● Open-closed ● Liskov substitution ● Interface segregation ● Dependency Inversion

Slide 7

Slide 7 text

Single Responsibility Principle (SRP) ● A module should be responsible to one, and only one, actor

Slide 8

Slide 8 text

SRP: Violation Employee -regularHours +calculatePay +reportHours +save Roy John Zune

Slide 9

Slide 9 text

SRP: Solution Employee Facade +calculatePay +reportHours +save PayCalculator +calculatePay HourReporter +reportHours EmployeeSaver +save

Slide 10

Slide 10 text

Open-closed Principle ● Open for extension but closed for modification ● Example with inheritance ○ Bad ○ Good

Slide 11

Slide 11 text

Liskov Substitution Principle ● If for each object o1 of type S, there is an object o2 of type T, such that, for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

LSP Violation Rectangle +setHeight +setWidth Square +setSides User

Slide 15

Slide 15 text

Interface Segregation Principle (ISP)

Slide 16

Slide 16 text

ISP Violation Ops +ops0 +ops1 +ops2 User0 User1 User2

Slide 17

Slide 17 text

Dependency Inversion Principle ● Source code should interact with abstractions, not concretions ● Stable vs volatile concrete elements

Slide 18

Slide 18 text

Takeaways ● Consider actors in the system ● Keep options open with layers ● Interact with abstractions over details