The 7 Things I Know About Cyber Security After 25 Years | April 2024
Code Like a Ninja Session 4 - Liskov Substitution Principle
1. CODE LIKE A NINJA
THE LISKOV SUBSTITUTION PRINCIPLE
2. 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-msharetrainingCode Like a Ninja
• Source was compiled using Visual Studio 2012
5. 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
6. 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.
7. 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.
9. 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-msharetrainingCode Like a Ninja
• Source was compiled using Visual Studio 2012
Editor's Notes
Basic srpExposeutils class antipatternExpose singleton as a bad pattern to use (use at own risk)