codecamp iasi 10 march 2012 - scratching-solid
DESCRIPTION
TRANSCRIPT
![Page 1: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/1.jpg)
Scratching SOLID
IULIAN TANASESCU-VLAD
10 / 03 / 2012
![Page 2: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/4.jpg)
SRP
![Page 5: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/7.jpg)
OCP
![Page 8: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/9.jpg)
OCP
![Page 10: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/10.jpg)
LSP
![Page 11: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/12.jpg)
ISP
![Page 13: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/14.jpg)
DIP
![Page 15: CodeCamp Iasi 10 march 2012 - Scratching-SOLID](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/16.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022051323/549bf62aac7959ec2a8b45e1/html5/thumbnails/17.jpg)
Please fill in the evaluation forms
Thank you!