Outline. Software Rots

Similar documents
Principles of OO Design

Single Responsibility Principle (SRP)

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

Produced by. Agile Software Development. Eamonn de Leastar

Bruno Bossola SOLID Design Principles

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

20 Years of. Improve the Design of your Code. Dr Dimitris Dranidis JAVA Meetup Group, Thessaloniki May 2015

OOD Smells and Principles

Ingegneria del Software Corso di Laurea in Informatica per il Management. Software quality and Object Oriented Principles

S.O.L.I.D. Principles of

Open Closed Principle (OCP)

OO Class Design Principles

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

17.11 Bean Rules persistent

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt

Agile Principles, Patterns, and Practices in C#

Software Engineering Design & Construction

Conception Orientée Objets. Programmation SOLID

Why Use Object-Oriented Programming in the First Place?

Object Design Guidelines

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4

Agile Software Development

Software Reengineering P1: Intro & Organization. Martin Pinzger Delft University of Technology

Contents. Unpleasant Code Smells. Refactoring

Design Patterns: Part 2

Principles of Object-Oriented Design

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

Object design. François Schwarzentruber ENS Cachan Antenne de Bretagne

S.O.L.I.D: Software Engineering Principles

Design Principles: Part 2

[Sample] Quality Report: <<project>>

Outline. Design Principles: Part 2. e.g. Rectangles and Squares. The Liskov Substitution Principle (LSP) ENGI 5895: Software Design.

1 Introduction 2 Complex Systems 3 Object Model 4 Dependency Management 5 Class Design. Object Oriented Programming in Physics

On Polymorphism and the Open-Closed Principle

CS 2340 Objects and Design

Object Oriented Software Design - I

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle

Course December Adrian Iftene

On Polymorphism and the Open-Closed Principle

Liskov Substitution Principle

Object-oriented design principles

Understading Refactorings

Highlights of Previous Lecture

On to Object-oriented Design

An Introduction to Processing

Object design. François Schwarzentruber ENS Cachan Antenne de Bretagne

Control Statements: Part Pearson Education, Inc. All rights reserved.

Design Principles: Part 2

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

Course 1 October, 9, Adrian Iftene

Language alone won t pay your bills. Alan Franzoni - EP 2012 twitter: franzeur website:

Refactoring and other small animals

CS 520 Theory and Practice of Software Engineering Fall 2018

Class Design Principles

Objectives: On completion of this project the student should be able to:

CSC207H: Software Design SOLID. CSC207 Winter 2018

Software Design and SOLID Principles

Common mistakes and Basic Design Principles. David Rabinowitz

Coverage of Part 2. A Brief Introduction to Java for C++ Programmers: Part 2. import: using packages

Solids as point set. Solid models. Solid representation schemes (cont d) Solid representation schemes. Solid representation schemes (cont d)

Model-View-Controller

SOFTWARE PATTERNS. Joseph Bonello

Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles

COURSE 11 DESIGN PATTERNS

11/4/15. Review. Objec&ves. Refactoring for Readability. Review. Liskov Subs&tu&on Principle (LSP) LISKOV SUBSTITUTION PRINCIPLE

Classes. Logistics. Feedback on ex0. Feedback on ex0. Feedback on ex0 -- logic. Ex2 - background. Test next week do not be late!

Build Testable Client and Service Applications

Design Patterns: State, Bridge, Visitor

Computer Graphics. Instructor: Oren Kapah. Office Hours: T.B.A.

CS 520 Theory and Practice of Software Engineering Fall 2017

Agile Architecture. The Why, the What and the How

Lecture 5 2D Transformation

CHAPTER 11 Refactoring

L4: Inheritance. Inheritance. Chapter 8 and 10 of Budd.

Nets and Drawings for Visualizing Geometry. Unit 1 Lesson 1

CISC 1600, Lab 2.2: Interactivity in Processing

16.1 Introduction... 2

Imagine you ve written a piece of code but then accidentally deleted and lost it.

Activity The Coordinate System and Descriptive Geometry

Learning from Home Activity Booklet

Geometry with Dash. Differentiated Task Cards Scaffolded On Level Challenge Hint Think Beyond. Michelle Eckstein

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

Best Practices for Code Handoffs

Development of Reverse Engineering System for Machine Engineering Using 3D Bit-map Data. Tatsuro Yashiki* and Tarou Takagi*

Outline. Design Patterns: Part 1. What is a Design Pattern? ENGI 5895: Software Design

Contents 1. Introduction 2 2. Solving equations Geometric proofs 20

NCTM Strands. NCTM Strands. NCTM Strands. Geometry. Number and Operations Algebra Geometry Measurement Data Analysis & Probability

Clean Code * * Or why is more important how we write code rather what we write. Assoc. prof. Catalin Boja, Asist. Bogdan Iancu, Lect.

Reengineering II. Transforming the System

Design Patterns. Paul Jackson. School of Informatics University of Edinburgh

Comp-361 : Game Programming Lecture 5

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

Geometry. Set 2. Daily Practice And Answer Keys

CSC324 Principles of Programming Languages

Create a Cool Vector Robot Character in Illustrator

The Object Oriented Paradigm

Refactoring Exercise

CHAPTER 5: PRINCIPLES OF DETAILED DESIGN

Properties. Circle of Knowledge

CS1004: Intro to CS in Java, Spring 2005

Transcription:

Outline Design Principles: Part 1 ENGI 5895: Software Design 1 The Need for Design Principles Andrew Vardy 2 Refactoring Faculty of Engineering & Applied Science Memorial University of Newfoundland January 24, 2018 3 Design Principles The Single-Responsibility Principle (SRP) The Open-Closed Principle (OCP) Symptoms of Poor Design Software Rots The following are the symptoms of bad software designs, as defined in Ch. 7 of [Martin, 2003]: Rigidity: The design is hard to change Fragility: The design is easy to break Immobility: The design is hard to reuse Viscosity: It is hard to do the right thing (i.e. forced into hacks) Needless Complexity: Overdesign Needless Repetition: Mouse abuse Needless Repetition: (Just kidding) Opacity: Disorganized expression When the requirements change, the system must change often in ways not anticipated by the initial design. Over time the software begins to acquire design smells... The software rots! The design should be kept as clean, simple, and as expressive as possible Never say, we ll fix that later...because you won t! When a requirement changes, the design should be updated to be resilient to that kind of change in the future Also known as design smells.

Refactoring The Single-Responsibility Principle (SRP) How do we modify our designs and our code to prevent rot. Refactoring... Refactoring...the process of changing a software system in such a way that it does not alter the external behaviour of the code yet improves its internal structure [Fowler, 1999] You can refactor code: e.g. Read ch. 5 of [Martin, 2003] You can refactor your design: We will see many examples Aclassshouldhaveonlyoneresponsibility. OR Aclassshouldhaveonlyonereasontochange. Aclasswithseveralresponsibilitiescreatesunnecessarycouplings between those responsibilities. e.g. Rectangle Class [Figure repeated] The Geometry Application is concerned with the mathematics of geometric shapes The Graphical Application may also involve some geometry, but it also needs to draw geometric shapes The Rectangle class has two responsibilities: Provide a mathematical model of a rectangle Render a rectangle Problems created: Inclusion: The GUI must be included in the Geometry Application (C++: linked into executable, Java: GUI.class file included in JAR file) A change required for one application may affect the other (e.g. adding a colour attribute)

e.g. Modem Interface Solution: Separate the two responsibilities (math rep. + drawing) into two separate classes interface Modem { void dial( String pno ); void hangup (); void send( char c ); char recv (); Multiple responsibilities? You could say there are two: Connection management (dial, hangup) Data transfer (send, recv) If connection management and data transfer are considered separate responsibilities then we can provide the following solution: [Figure repeated] However, what if connection management and data transfer always change together? Then Modem has only one reason for change and can be left as is. To modify Modem in this case would smell of needless complexity. Consider our solution again. Modem Implementation has two responsibilities! Isn t this bad? Yes but... This may be unavoidable due to h/w or OS constraints Even if Modem Implementation changes, other classes in the system should remain unaffected

The Need for Design Principles Refactoring Design Principles The Open-Closed Principle (OCP) Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. OR To change behaviour, add new code rather than changing existing code. References e.g. Client Server With regards to the Client, the following design does not conform to the OCP. If we want the Client to use a different Server, we must change the Client. However, the following design resolves this problem: How? Abstraction. The DrawShape function violates the OCP: class Shape { enum ShapeType { SQUARE, CIRCLE itstype ; Shape ( ShapeType t ) : itstype ( t ) { ; class Circle : public Shape { Circle ( ) : Shape ( CIRCLE ) { ; void Draw ( ) ; ; class Square : public Shape { Square ( ) : Shape ( SQUARE ) { ; void Draw ( ) ; ; void DrawShape ( const Shape& s ) { if ( s. itstype == Shape : : SQUARE ) static_cast<const Square&>(s ). Draw ( ) ; else if ( s. itstype == Shape : : CIRCLE ) static_cast<const Circle&>(s ). Draw ( ) ; New derivatives of Shape require changes to DrawShape. The use of virtual methods solves this problem: class Shape { virtual void Draw ( ) const = 0 ; ; class Square : public Shape { virtual void Draw ( ) const ; ; class Circle : public Shape { virtual void Draw ( ) const ; ; void DrawShape ( const Shape& s ) { s. Draw ( ) ;

References Martin Fowler. Refactoring: Improving the Design of Existing Code. Addison-Wesley, 1999. Robert C. Martin. Agile Software Development: Principles, Patterns, and Practices. Prentice Hall, 2003.