Code Like a Ninja Session 4 - Liskov Substitution Principle
-
Upload
deon-meyer -
Category
Technology
-
view
150 -
download
0
Transcript of Code Like a Ninja Session 4 - Liskov Substitution Principle
![Page 1: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/1.jpg)
CODE LIKE A NINJATHE LISKOV SUBSTITUTION PRINCIPLE
![Page 2: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/2.jpg)
SESSION RESOURCES
• Presentation session notes including link to this session, will be available on http://learningaboutfudge.blogspot.com
• All the source for this session is publically available at: https://github.com/SheepWorx/Training
• RSS Feed: http://learningaboutfudge.blogspot.com/feeds/posts/default?alt=rss
• Local Network: \\dmeyer-m\share\training\Code Like a Ninja
• Source was compiled using Visual Studio 2012
![Page 3: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/3.jpg)
Single Responsibility PrincipleOpen/Close PrincipleLiskov’s Substitution PrincipleInterface Segregation PrincipleDependency Inversion Principle
![Page 4: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/4.jpg)
![Page 5: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/5.jpg)
DEFINITION
The Liskov Substitution Principle
Functions that use references to base classes must be able to use objects of derived classes without knowing it
Laymen’s Terms
You must be able to apply the same code in a function, where that function takes the base object as a parameter, to all super instances of that base object without having to make a distinction between them
![Page 6: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/6.jpg)
WHY?
• LSP primarily exists because of the SRP and OCP.
• Issues that exist by violating the LSP are not always apparent when initially designing the code.
• Issues that violate the LSP may introduce serious maintenance and design expansion issues in the future.
![Page 7: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/7.jpg)
CODE
• See the three examples about LSP violation and the possible serious ramifications that it might have down the line
• Note that not all violations are obvious and some can only be seen once the actual issue has arisen.
![Page 8: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/8.jpg)
Next Session: S.O.L.I.D – Interface Segregation Principle
![Page 9: Code Like a Ninja Session 4 - Liskov Substitution Principle](https://reader034.fdocuments.in/reader034/viewer/2022052621/55823854d8b42a0d368b4ba4/html5/thumbnails/9.jpg)
SESSION RESOURCES
• Presentation session notes including link to this session, will be available on http://learningaboutfudge.blogspot.com
• All the source for this session is publically available at: https://github.com/SheepWorx/Training
• RSS Feed: http://learningaboutfudge.blogspot.com/feeds/posts/default?alt=rss
• Local Network: \\dmeyer-m\share\training\Code Like a Ninja
• Source was compiled using Visual Studio 2012