Liskov Substitution Principle Jon McBee CLA, CLED, CTD, CPI, LabVIEW Champion.

Slides:



Advertisements
Similar presentations
Design Principles & Patterns
Advertisements

Since 1995, we’ve been building innovative custom solutions specifically designed to meet the unique needs of America’s most recognized companies. If you.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
SOLID Object Oriented Design Craig Berntson
Error Management with Design Contracts Karlstad University Computer Science Error Management with Design Contracts Eivind J. Nordby, Martin Blom, Anna.
17.10 Java Beans Java beans are a framework for creating components in Java. AWT and Swing packages are built within this framework Made to fit in with.
1 Software Maintenance and Evolution CSSE 575: Session 6, Part 1 The “SEAM” Model Steve Chenoweth Office Phone: (812) Cell: (937)
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
On the Relation between Design Contracts and Errors Karlstad University Computer Science On the Relation Between Design Contracts and Errors A Software.
Liskov Substitution Principle
Ch4: Software Architecture and Design. 1 What is a design?
Systems Design. Analysis involves understanding and documenting user requirements in a clear and unambiguous way. It focuses on the business side and.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
CLASS DESIGN PRINCIPLES Lecture 2. The quality of the architecture What is a good design? It is the design that at least does not have signs of “bad”.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
Company Confidential – Do Not Duplicate 2 Copyright 2008 McLane Advanced Technologies, LLC S.O.L.I.D. Software Development Achieving Object Oriented Principles,
Lecture 16 Composition vs Inheritance: The Final Chapter.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
CSE 301 Exam Revision Lecture
Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.
Systems Analysis & Design Methods VII OOD-principles.
CSCI 383 Object-Oriented Programming & Design Lecture 17 Martin van Bommel.
S.O.L.I.D. Software Development 12 January 2010 (Martin Verboon, Patrick Kalkman, Stan Verdiesen)
Башкирцев (Старовер) Станислав JavaTalks OOD Principles.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Design Principles iwongu at gmail dot com.
The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
 What is SOLID  The S in SOLID  The O in SOLID  The L in SOLID  The I in SOLID  The D in SOLID  Questions.
Software Design Principles
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Elements of OO Abstraction Encapsulation Modularity Hierarchy: Inheritance & Aggregation 4 major/essential elements3 minor/helpful elements Typing Concurrency.
OO Design Principles Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 11a: Component-Level Design Software Engineering: A Practitioner’s Approach, 6/e Chapter.
Design for testability as a way to good coding Simone Chiaretta Architect, Council of the EU December 9 th,
Five design principles
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
CHAPTER 3 MODELING COMPONENT-LEVEL DESIGN.
Component Design Elaborating the Design Model. Component Design Translation of the architectural design into a detailed (class-based or module- based)
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
SOLID Design Principles
Dependency Inversion Principle Jon McBee Principal Software Engineer Ultratech CNT.
Session 33 More on SOLID Steve Chenoweth Office: Moench Room F220 Phone: (812) Chandan Rupakheti Office: Moench.
Dependency Inversion By Steve Faurie. Dependency Inversion Described in Agile Principles, Patterns and Practices in C# by Robert C. Martin.
SOLID PHP & Code Smell Wrap-Up
Microsoft Advertising 16:9 Template Light Use the slides below to start the design of your presentation. Additional slides layouts (title slides, tile.
Clean Code and How to Achieve Zero Defects Jason Jolley Director, Application Development Micro Strategies, Inc.
Beginning Software Craftsmanship Brendan Enrick Steve Smith
Mantas Radzevičius ifm-2/2
Course information Old exam Resit Report Result and walkthrough
Dependency Inversion Principle
Software Design Principles
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Copyright © by Curt Hill
Software Engineering: A Practitioner’s Approach, 6/e Chapter 11 Component-Level Design copyright © 1996, 2001, 2005 R.S. Pressman & Associates, Inc.
Object Oriented Practices
Software Design Principles
Object Oriented Practices
Principles of Object-Oriented Design
The SOLID Principles.
A (partial) blueprint for dealing with change
Principles of Object-Oriented Design
1.
Dependency Inversion principle
Some principles for object oriented design
Liskov Substitution Principle (LSP)
Chapter 10 – Component-Level Design
Presentation transcript:

Liskov Substitution Principle Jon McBee CLA, CLED, CTD, CPI, LabVIEW Champion

Liskov Substitution Principle (LSP) If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.

Liskov Substitution Principle S is not a valid subtype of T if the behavior of P changes when T is replaced with S “Functions that use base classes must be able to use objects of derived classes without knowing it” – Robert C. Martin

Analogy

DC Device 5mm AC Adapter Interface +5mm Adapter Panasonic +2V +5A +Positive Polarity Sony +5V +2A +Positive Polarity Samsung +100V +0.1A +Negative Polarity

Analogy Functions that use base classes must be able to use objects of derived classes without knowing it

Liskov Substitution Principle +2V +5A +5V +2A +100V +0.1A S is not a valid subtype of T if the behavior of P changes when T is replaced with S DC Device 5mm AC Adapter Interface +5mm Adapter Panasonic +2V +5A +Positive Polarity Sony +5V +2A +Positive Polarity Samsung +100V +0.1A +Negative Polarity S T P

Dependency Inversion Principle: Part B +2V +5A +5V +2A +100V +0.1A DC Device 5mm AC Adapter Interface +5mm Adapter Panasonic +2V +5A +Positive Polarity Sony +5V +2A +Positive Polarity Samsung +100V +0.1A +Negative Polarity

Liskov Substitution Principle = =

 LSP violations impact the flexibility of our software  LSP violations are difficult to predict  LSP violations should be detectable with unit testing

LSP in the Wild

Caraya  A new take on unit testing by JKI  Turn your sandbox code into unit test code  Unit test your code without interrupting your workflow  On Github:

Summary  A function that depends on an abstract class as a source code dependency must be able to use a child of that abstraction as a run time dependency without knowing it  LSP effects both the function calling the abstraction, and the child classes implementing the abstraction  Any code using an abstraction must assume nothing else beyond the defined abstraction  Any implementation of an abstraction must adhere to the requirements and conventions of the interface to the abstraction  LSP violations are easier to avoid when following DIP part B  Abstractions should not depend on details, details should depend on abstractions  The high level module should define the interface, not the details  The compiler won’t show you LSP violations  LSP violations are hard to foresee when writing code, but can be detected with unit testing