Copyright © by Curt Hill

Slides:



Advertisements
Similar presentations
Chapter 11 Component-Level Design
Advertisements

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
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
TEST-1 7. Object-Oriented Design Principles. TEST-2 The Pillars of the Paradigm Abstraction Encapsulation Hierarchy –Association, Aggregation –Inheritance.
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,
OODP Prudent OO Design. OODP-2 The Pillars of the Paradigm Abstraction Encapsulation Hierarchy –Association, Aggregation –Inheritance Polymorphism.
Design Design and Software Architecture. The design phase The analysis phase describes what the system should be doing The design phase describes how.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.
CSSE 374: More GRASP’ing for Object Responsibilities
S.O.L.I.D. Software Development 12 January 2010 (Martin Verboon, Patrick Kalkman, Stan Verdiesen)
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Design Principles iwongu at gmail dot com.
 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.
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
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,
High Cohesion Low Coupling Old Standards for Object Oriented Programming.
Five design principles
CHAPTER 3 MODELING COMPONENT-LEVEL DESIGN.
Principles of Object Oriented Design
Component Design Elaborating the Design Model. Component Design Translation of the architectural design into a detailed (class-based or module- based)
SOLID Design Principles
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Session 33 More on SOLID Steve Chenoweth Office: Moench Room F220 Phone: (812) Chandan Rupakheti Office: Moench.
1 Advanced Object- oriented Design – Principles CS320 Fall 2005.
1 Advanced Object-oriented Design – Principles and Patterns OO Design Principles.
Mantas Radzevičius ifm-2/2
OCP and Liskov Principles
Copyright © Jim Fawcett Spring 2017
Web Design & Development Lecture 9
Sections Inheritance and Abstract Classes
Software Design Principles
Chapter 12 Object Oriented Design Principles
Objects First with Java A Practical Introduction using BlueJ
Software Architecture & Difference from Design
Chapter 12 Object Oriented Design Principles
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Chapter 11 Object-Oriented Design
Software Engineering: A Practitioner’s Approach, 6/e Chapter 11 Component-Level Design copyright © 1996, 2001, 2005 R.S. Pressman & Associates, Inc.
Not what first comes to mind
The Object-Oriented Thought Process Chapter 08
SE-2811 Software Component Design
Object Oriented Practices
Component-Level Design
Software Design Principles
lecture 08, OO Design Principle
Chapter 20 Object-Oriented Analysis and Design
Design Tips.
Unit 6 Assignment 2 Chris Boardley.
Object Oriented Practices
Object Oriented Practices
The SOLID Principles.
A (partial) blueprint for dealing with change
Principles of Object-Oriented Design
Dependency Inversion principle
Some principles for object oriented design
Chapter 8 - Design Strategies
Liskov Substitution Principle (LSP)
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Chapter 10 – Component-Level Design
Presentation transcript:

Copyright © 2015-2016 by Curt Hill S. O. L. I. D. As a Rock Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Introduction The SOLID acronym has been called the first five principles of OO Design Introduced by Robert Martin Acronym by Michael Feathers Before we consider this lets consider bad design Copyright © 2015-2016 by Curt Hill

Three Traits of Bad Design Rigidity It is hard to change because every change affects too many other parts of the system Fragility When you make a change, unexpected parts of the system break. Immobility It is hard to reuse in another application because it cannot be disentangled from the current application Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill SOLID S – Single Responsibility principle O – Open Closed principle L – Liskov Substitution principle I – Interface Segregation principle D – Dependency Inversion principle Copyright © 2015-2016 by Curt Hill

Single Responsibility A class should have only a single responsibility It should do just one thing One alternative to responsibility that is suggest is a reason to change If you can think of more than one motive for changing a class, then that class has more than one responsibility If a class has multiple responsibilities we say that they are coupled Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Example We have a Rectangle class that is used by two other classes A computational geometry class A GUI drawing class The Rectangle class now has two distinct responsibilities Provide a model for of geometry Provide the ability to draw on a surface If the GUI drawing class changes we may need to also change geometry class Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill More Coupled responsibilities tend to lead to fragility A change in one class forces a change in another This may cause breakage Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Open Closed You should be able to extend a classes behavior without modifying it Modules should be designed to never change If the code works leave it alone When requirements change the behavior is extended Add new code but not by changing code that works Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Extensions Extensions take mostly two forms We add a new method that may utilize some of the existing and working code We derive a new class from the existing class and add extensions there Violations of this principle tend to cascade changes into other modules, which often break The code becomes fragile Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Liskov Substitution Derived classes must be substitutable for their base classes Any module that uses a class, should be able to use any descendent class without knowing it Attributed to Barbara Liskov, a recent Turing award winner Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Violations When the Liskov substitution principle is is violated then the module must know about all the descendants Even those not created when the module was designed What we typically see in this case is lots of Ifs that determine the type of the object This is a bad thing Copyright © 2015-2016 by Curt Hill

Digression on Interfaces An interface in a general sense is that collection of public methods that a class presents An Abstract Base Class is an interface In Java there is an Interface construct which is a contract An implementing class promises to provide certain methods In C++ we do not need the Interface We have multiple inheritance Copyright © 2015-2016 by Curt Hill

Interface Segregation Make fine grained interfaces that are client specific We would like our interfaces to be cohesive Non-cohesive interfaces typically have groups of interfaces Different clients will use different groups of interfaces Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Interface Pollution Interface pollution is when a class has an interface that only some of its sub-classes require Consider the door example next Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Doors Suppose we want a door class It may be locked or unlocked It may be open or closed Now we derive from that a timed door that sounds an alarm if the door is open too long The timed door registers with a a timer object When the time elapses the timer object does a call of a method to alert the timed door object Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Door Again We create a timer client We then derive door from that We then derive timed door from door Now door has a timer client that it does not need Its subclass does, but not it This is an example of interface pollution Door has been polluted with what it does not need Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Continuing Timer client was one interface while door was another They are completely different Thus they should be separated, ie. Interface Segregation Stated again, the Interface Segregation Principle says that clients should not be forced to depend on interfaces that they do not use Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Dependency Inversion High level modules should not depend upon low level modules Both should depend on abstractions Abstractions should not depend on details Details should depend on abstractions Said another way Concrete classes may depend on abstract classes or on concrete classes Abstract classes should not depend on concrete classes Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Layers In many software systems we have layers Such as operating systems Each layer provides an interface to the upper layer Each layer uses the lower layer to accomplish the tasks This is a well known technique Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Inversion? The layering appears to make more abstract things dependent on more concrete items In the Dependency Inversion Principle we are not considering the same thing Rather we are talking about interface dependencies Copyright © 2015-2016 by Curt Hill

Copyright © 2015-2016 by Curt Hill Finally These five principles form a foundation for object design Like several “rules of thumb” they may be violated But only with very good cause Convenience is not such a cause These are principles we will also apply in refactoring Finally for now Copyright © 2015-2016 by Curt Hill