Interface Segregation Principle

Slides:



Advertisements
Similar presentations
Chapter 11 Component-Level Design
Advertisements

Design Principles & Patterns
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Efficient, Productive, Time-Saving Solutions TRANSACTION AUDITING Part of our RISK MANAGEMENT SUITE FOR LAWSON S3 Thank you for taking the time to view.
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
Inheritance Inheritance Reserved word protected Reserved word super
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Inheritance issues SE-2811 Dr. Mark L. Hornick 1.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
1 © Talend 2014 Service Locator Talend ESB Training 2014 Jan Bernhardt Zsolt Beothy-Elo
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Object-oriented metrics Design decisions: Class Cohesion Open-Closed Single Responsibility Interface Segregation Dependency Inversion Liskov Substitution.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
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,
Partitioning and Layering Fundamentals. The Basic Problem Change is a fact of life RequirementsTechnologies Bug Fixes Software Must Adapt.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
CSE 301 Exam Revision Lecture
Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.
Test Isolation and Mocking Technion – Institute of Technology Author: Gal Lalouche © 1 Author: Gal Lalouche - Technion 2015 ©
S.O.L.I.D. Software Development 12 January 2010 (Martin Verboon, Patrick Kalkman, Stan Verdiesen)
Башкирцев (Старовер) Станислав JavaTalks OOD Principles.
SOLID Principles in Software Design
DAAD project “Joint Course on OOP using Java” On Object Oriented modeling in Java (Why & How) Ana Madevska Bogdanova Institute of informatics Faculty of.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Code reading skills LEVEL GAME.  Common scenario:  Students raise hand. Point to code, say they don’t understand why it’s not working.  public void.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
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.
High Cohesion Low Coupling Old Standards for Object Oriented Programming.
Five design principles
Principles of Object Oriented Design
PRINCIPLES OF OBJECT ORIENTED DESIGN S.O.L.I.D. S.O.L.I.D Principles What is SOLID?  Acrostic of 5 Principles:  The Single Responsibility Principle.
SOLID Design Principles
SOLID Principles in Software Design
Observer Pattern Keeping An Eye on Things Need to introduce observer pattern formally first, include book definition & design principle Keeping An Eye.
SOLID PHP & Code Smell Wrap-Up
Principled N-Tier Design or, a Solution to the Solution Problem Steve | ardalis.com Telerik, Inc.
Beginning Software Craftsmanship Brendan Enrick Steve Smith
1 Advanced Object-oriented Design – Principles and Patterns OO Design Principles.
Mantas Radzevičius ifm-2/2
Interface Segregation / Dependency Inversion
OCP and Liskov Principles
Course information Old exam Resit Report Result and walkthrough
Object-Orientated Analysis, Design and Programming
IF-less programming in C#
JS Apps Online Team "Fortress"
Software Architecture & Difference from Design
Design Patterns Lecture part 2.
Copyright © by Curt Hill
Object Oriented Practices
Component-Level Design
دانشگاه شهیدرجایی تهران
11/29/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Object Oriented Design Patterns - Structural Patterns
تعهدات مشتری در کنوانسیون بیع بین المللی
Design Patterns Lecture part 1.
Adapter Design Pattern
A (partial) blueprint for dealing with change
Object Oriented Design & Analysis
1.
Dependency Inversion principle
HFOOAD Chapter 5 Interlude
S. Single Responsibility Principle O. L. I. D.
Chapter 10 – Component-Level Design
Presentation transcript:

Interface Segregation Principle

Definition Clients should not be forced to depend on methods they do not use. Prefer small, cohesive interfaces to “fat” interfaces. ISP helps you resolve the problem with LSP violations. www.seavus.com

Motivational poster

Motivational poster

Interfaces Why interfaces exist? Who owns the interfaces? Who defines the interfaces? Should we think about interfaces in terms of the concrete classes that implement those interfaces? www.seavus.com

Interfaces The purpose of the interfaces in the first place is to introduce loose coupling. It’s not really the concrete class that needs the interface – it’s the client that needs the interface. The client owns the interface! The client defines what it needs! www.seavus.com

Example 1

Problems ReadOnlyStream needs to provide implementation of the write() method, even though it does not require them. This is a violation of the Interface Segregation Principle. Violation of the Interface Segregation Principle also leads to violation of the complementary Open Closed Principle. For example, consider that the Stream interface is modified to include a new method. As a result, you now need to modify all existing Stream implementation classes to include the new method even if they do not need it. www.seavus.com

Following the Interface Segregation Principle

Example 2 Both clients HAVE A CustomerTransaction object Both clients don’t required all of the methods from CustomerTransaction www.seavus.com

Example 2 www.seavus.com

So, what’s the problem? www.seavus.com

Problems Changes in the CustomerTransaction class could result in recompilation and redeployment of both of this dependent client modules. For example, if we update method: chargeCustomer( String arg ), TransactionReportGenerator will be forced to recompile and redeploy although it doesn’t use this method. www.seavus.com

Solution www.seavus.com

Demo www.seavus.com

When to fix ISP Once there is pain If there is no pain, there’s no problem to address If you find yourself depending on a “fat” interface you own Create a smaller interfaces with just what you need Have the fat interface implement your new interface Reference the new interface with your code If you find “fat” interfaces are problematic but you do not own them Create a smaller interface with just what you need Implement this interface using an Adapter that implements the full interface (adapter would be between you and the third party interface that you don’t have control over) www.seavus.com

ISP tips Keep interfaces small, cohesive and focused (refactor large interfaces so they inherit smaller interfaces) Whenever possible, let the client define the interface (don’t force client code to depend on things it doesn’t need) www.seavus.com

Thank you for your attention Copyright: © 2019 Seavus. All rights reserved. | www.seavus.com | info@seavus.com | sales@seavus.com