The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)
-
Upload
madison-king -
Category
Documents
-
view
214 -
download
0
Transcript of The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)
![Page 1: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/1.jpg)
The benefits of SOLID in software development
Ruben Agudo Santos (GS-AIS-HR)
![Page 2: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/2.jpg)
Table of contents
What is SOLID?
Single Responsibility Principle
Open-Closed Principle
Liskov’s Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Why we should care
QA
Bibliography
![Page 3: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/3.jpg)
What is SOLID?
Uncle Bob
Not a state of matter
![Page 4: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/4.jpg)
Single Responsibility Principle
“THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE”
![Page 5: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/5.jpg)
Single Responsibility Principle
BROKE
N!!
![Page 6: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/6.jpg)
Single Responsibility Principle
![Page 7: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/7.jpg)
Open-Closed Principle
“SOFTWARE ENTITIES SHOULD BE OPEN FOR EXTENSION, BUT CLOSED FOR MODIFICATION”
![Page 8: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/8.jpg)
Open-Closed Principle
public void DrawAllShapes(Shape[] shapes) {
for (int i = 0; i < shapes.length; i++) {
Shape s = shapes[i];
switch(s.itsType) {
case Shape.SQUARE:
drawSquare((Square) s);
break;
case Shape.CIRCLE:
drawCircle((Circle) s);
break;
}
}
}
BROKE
N!!
![Page 9: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/9.jpg)
Open-Closed Principle
public void DrawAllShapes(Shape[] shapes) {
for (int i = 0; i < shapes.length; i++) {
Shape s = shapes[i];
s.draw();
}
}
![Page 10: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/10.jpg)
Liskov Substitution Principle
“FUNCTIONS THAT USE POINTERS OR REFERENCES TO BASE CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT”
![Page 11: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/11.jpg)
Liskov Substitution Principle
![Page 12: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/12.jpg)
Liskov Substitution Principle
Moral of the story:
Model the classes based on behavior.
“...when redefining a routine [in a derivative], you may only replace its precondition by a weaker one, and its postcondition by a stronger one.”
![Page 13: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/13.jpg)
Interface Segregation Principle
“CLIENTS SHOULD NOT BE FORCED TO DEPEND UPON INTERFACES THAT THEY DO NOT USE”
![Page 14: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/14.jpg)
Interface Segregation Principle
BROKE
N!!
![Page 15: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/15.jpg)
Interface Segregation Principle
![Page 16: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/16.jpg)
Dependency Inversion Principle
A. “HIGH LEVEL MODULES SHOULD NOT DEPEND UPON LOW LEVEL MODULES. BOTH SHOULD DEPEND UPON ABSTRACTIONS”
B. “ABSTRACTIONS SHOULD NOT DEPEND UPON DETAILS. DETAILS SHOULD DEPEND UPON ABSTRACTIONS”
![Page 17: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/17.jpg)
Dependency Inversion Principle
void Copy() {
int c;
while ((c = readKeyboard()) != EOF) {
writePrinter(c);
}
}
![Page 18: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/18.jpg)
Dependency Inversion Principle
enum OutputDevice {printer, disk};
void Copy(outputDevice dev) {
int c;
while ((c = ReadKeyboard()) != EOF)
if (dev == printer) WritePrinter(c);
else WriteDisk(c);
}BROKE
N!!
![Page 19: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/19.jpg)
Dependency Inversion Principle
abstract class Reader {
public abstract int read();
};
abstract class Writer {
public abstract void write(char);
};
void copy(Reader r, Writer w) {
int c;
while((c=r.Read()) != EOF)
w.Write(c);
}
![Page 20: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/20.jpg)
Why we should care
Cleaner code (Remember Ben Wolff’s presentation)
Code smells are kept away
Codebase that is maintainable and expandable
Usually integrated in Agile methodologies, i.e. Scrum
![Page 21: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/21.jpg)
QA
THANKS FOR COMING!
![Page 22: The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)](https://reader036.fdocuments.us/reader036/viewer/2022062517/56649f115503460f94c23ce2/html5/thumbnails/22.jpg)
Bibliography
Robert C. Martin
http://www.objectmentor.com/resources/articles/srp.pdf
http://www.objectmentor.com/resources/articles/ocp.pdf
http://www.objectmentor.com/resources/articles/lsp.pdf
http://www.objectmentor.com/resources/articles/isp.pdf
http://www.objectmentor.com/resources/articles/dip.pdf
Duck Panel
https://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures /
Robert C. Martin Photo
Uploaded by Tim-bezhashvyly, under CC BY-SA 4.0