codecamp iasi 10 march 2012 - scratching-solid

17
Scratching SOLID IULIAN TANASESCU-VLAD 10 / 03 / 2012

Upload: codecampiasi

Post on 25-Dec-2014

551 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

Scratching SOLID

IULIAN TANASESCU-VLAD

10 / 03 / 2012

Page 2: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

So … what is SOLID?

Five basic principles of object-oriented programming and design.

Single responsibility principle

Open/closed principle

Liskov substitution principle

Interface segregation principle

Dependency inversion principle

Page 3: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

Who put them together?

What do you know … it's Uncle Bob!

Robert C. Martin http://objectmentor.com/omTeam/martin_r.html

Page 4: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

SRP

Page 5: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

SRP

Every object should have a single responsibility and that responsibility should be entirely encapsulated by the class.

Wikipedia

Responsibility!? … not again

Ah … a reason to change

Page 6: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

SRP

“a measure of how strongly-related or focused the responsibilities of a single module are”

COHESION!

Page 7: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

OCP

Page 8: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

OCP

Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.

Wikipedia

Open and closed … another paradox!?

New functionality can be added as new requirements are generated.

Never modify the code except to correct bugs.

Page 9: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

OCP

Page 10: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

LSP

Page 11: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

LSP

If S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of that program (correctness, task performed, etc.)

Wikipedia

That sounds so ... formal!

Code that uses a base class must be able to substitute it with a subclass without knowing it.

Page 12: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

ISP

Page 13: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

ISP

Once an interface has become too 'fat' it needs to be split into smaller and more specific interfaces.

Wikipedia

Why!?

COHESION!

No client should be forced to depend on methods it does not use.

Page 14: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

DIP

Page 15: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

DIP

A. High-level modules should not depend on low-level modules. Both should depend on abstractions.B. Abstractions should not depend upon details. Details should depend upon abstractions.

Wikipedia

Page 16: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

DIP

“a degree to which each program module relies on each one of the other modules”

COUPLING!

Page 17: CodeCamp Iasi 10 march 2012 - Scratching-SOLID

Please fill in the evaluation forms

Thank you!