introduction to solid principles. background dependency inversion principle single responsibility...
TRANSCRIPT
![Page 1: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/1.jpg)
Introduction to SOLID Principles
![Page 2: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/2.jpg)
Background
![Page 3: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/3.jpg)
• Dependency Inversion Principle
• Single Responsibility Principle
• Open/Closed Principle
• Liskov Substitution Principle
• Interface Segregation Principle
![Page 4: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/4.jpg)
S: Single Responsibility Principle (SRP)
“Every class should have a single responsibility, and that responsibility should be entirely encapsulated by that class”
![Page 5: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/5.jpg)
![Page 6: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/6.jpg)
1. When we need to modify the way we save Customer data
2. When we want to revise the way we log our Exceptions
The Customer class has 2 reasons to change:
![Page 7: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/7.jpg)
![Page 8: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/8.jpg)
![Page 9: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/9.jpg)
Difficulty in naming classes can be a sign that you are trying to do too much, and that this class is taking on too much responsibility
Do One Thing: methods that only do one thing are usually very short: 3-5 lines
Multiple unit tests for the same method should be a warning sign that you are doing too much
SRP - Tips
![Page 10: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/10.jpg)
O: Open/Closed Principle (OCP)
“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”
![Page 11: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/11.jpg)
O: Open/Closed Principle (OCP)
Open for extension – you can extend an object’s behaviour
Closed for modification – without the need to modify any existing code
![Page 12: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/12.jpg)
![Page 13: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/13.jpg)
![Page 14: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/14.jpg)
![Page 15: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/15.jpg)
L: Liskov Substitution Principle (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”
![Page 16: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/16.jpg)
![Page 17: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/17.jpg)
![Page 18: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/18.jpg)
![Page 19: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/19.jpg)
![Page 20: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/20.jpg)
![Page 21: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/21.jpg)
Favour Interfaces over inheritance (Google this…you’ll find loads!)
Use inheritance sparingly.
Keep inheritance hierarchies from getting to big – aim for no more than two or three deep.
LSP - Tips
![Page 22: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/22.jpg)
I: Interface Segregation Principle (ISP)
“No client should be forced to depend on methods it does not use.”
![Page 23: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/23.jpg)
![Page 24: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/24.jpg)
![Page 25: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/25.jpg)
![Page 26: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/26.jpg)
![Page 27: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/27.jpg)
![Page 28: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/28.jpg)
![Page 29: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/29.jpg)
D: Dependency Inversion Principle (DIP)
“A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend on details. Details should depend on abstractions.”
![Page 30: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/30.jpg)
![Page 31: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/31.jpg)
![Page 32: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/32.jpg)
![Page 33: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/33.jpg)
UnityCastle Windsor
IOC Containers
![Page 34: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/34.jpg)
![Page 35: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/35.jpg)
Questions
![Page 36: Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution](https://reader035.vdocuments.net/reader035/viewer/2022081419/56649ee75503460f94bf8109/html5/thumbnails/36.jpg)
Follow UsDave Cook
http://tech.comparethemarket.com/author/cookie/
@dcook_net
@thectmers