code like a ninja session 4 - liskov substitution principle

9
CODE LIKE A NINJA THE LISKOV SUBSTITUTION PRINCIPLE

Upload: deon-meyer

Post on 18-Jun-2015

151 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Code Like a Ninja Session 4 - Liskov Substitution Principle

CODE LIKE A NINJATHE LISKOV SUBSTITUTION PRINCIPLE

Page 2: Code Like a Ninja Session 4 - 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

Page 3: Code Like a Ninja Session 4 - Liskov Substitution Principle

Single Responsibility PrincipleOpen/Close PrincipleLiskov’s Substitution PrincipleInterface Segregation PrincipleDependency Inversion Principle

Page 4: Code Like a Ninja Session 4 - Liskov Substitution Principle
Page 5: Code Like a Ninja Session 4 - Liskov Substitution 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

Page 6: Code Like a Ninja Session 4 - Liskov Substitution Principle

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

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

Next Session: S.O.L.I.D – Interface Segregation Principle

Page 9: Code Like a Ninja Session 4 - 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