code like a ninja session 4 - liskov substitution principle
TRANSCRIPT
CODE LIKE A NINJATHE LISKOV SUBSTITUTION PRINCIPLE
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
Single Responsibility PrincipleOpen/Close PrincipleLiskov’s Substitution PrincipleInterface Segregation PrincipleDependency Inversion Principle
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
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.
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.
Next Session: S.O.L.I.D – Interface Segregation Principle
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