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

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

Principles of Object-Oriented Design

The Release Reuse Equivalency Principle (REP) The Common Closure Principle (CCP) The Common Reuse Principle (CRP)

Principles of Object-Oriented Design

OO Class Design Principles

Bruno Bossola SOLID Design Principles

Dependency Inversion Principle (DIP) Package Design: Coupling Principles

OO Package Design Principles

UML and Design Patterns Prof. Dr. Eric Dubuis, V. June Engineering and Information Technology. On Package Design

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Agile Software Development

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

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

Highlights of Previous Lecture

17.11 Bean Rules persistent

Object-oriented design principles

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

Outline. Software Rots

Object-Oriented Design

Objec&ves. Review. Liskov Subs&tu&on Principle Refactoring for Extensibility. What are reasons that we refactor our code?

CSC207H: Software Design SOLID. CSC207 Winter 2018

Component-Level Design. Slides copyright 1996, 2001, 2005, 2009 by Roger S. Pressman. For non-profit educational use only

Stability. Introduction

Intro to: Design Principles

Agile Principles, Patterns, and Practices in C#

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

09. Component-Level Design

Software Engineering

Object-Oriented Design

CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures)

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

Lecture: Modular Design

Conception Orientée Objets. Programmation SOLID

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

Software Engineering CSC40232: SOFTWARE ENGINEERING. Guest Lecturer: Jin Guo SOLID Principles sarec.nd.edu/courses/se2017

SOLID: Principles of OOD

Design patterns. François Schwarzentruber ENS Cachan Antenne de Bretagne

Principles of OO Design

Lessons Learned. Johnny Bigert, Ph.D., Skype/Microsoft October 26, 2011

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

The de constructed. Magento module

PRINCIPLES OF SOFTWARE DESIGN

CMPE/SE 135 Object-Oriented Analysis and Design

a correct statement? You need to know what the statement is supposed to do.

Setting the stage... Key Design Issues. Main purpose - Manage software system complexity by improving software quality factors

Performance-related aspects in the Big Data Astronomy Era: architects in software optimization

Principles of Software Design. Software Engineering Alessio Gambi Saarland University

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

Granularity. Inheritance Bi-directional. Association. Derived A1

OO Technology: Properties and Limitations for Component-Based Design

Living and Working with Aging Software. Ralph Johnson. University of Illinois at Urbana-Champaign

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

Top 7 Lessons From My First Big Silverlight Project

Design Principles: Part 2

Readability [Skrien 4.0] Programs must be written for people to read, and only incidentally for machines to execute.

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

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

CS 32. Lecture 1: oops

Object-Oriented Design I - SOLID

Qualifying Exam Languages

Design Principles: Part 2

Why Use Object-Oriented Programming in the First Place?

CSE wi Midterm Exam 2/8/18. Name UW ID #

CS 307: Software Engineering. Lecture 10: Software Design and Architecture

MITOCW watch?v=zm5mw5nkzjg

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

More on object orientation

Open Closed Principle (OCP)

CSE 331 Final Exam 3/16/15 Sample Solution

Maintainable Software. Software Engineering Andreas Zeller, Saarland University

Announcements. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Intuition: Type Signature is a Specification.

CPSC 410? Advanced Software Engineering Mid-term Examination (Term I ) SOLUTION Instructor: Gail Murphy

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

SOLID Principles. Equuleus Technologies. Optional Subheading October 19, 2016

Software Design and SOLID Principles

Hoare Logic: Proving Programs Correct

OO Design Principles

(Practical) SW Architectures. November 14, 2013

EXAMINATIONS 2012 END-OF-YEAR SWEN222. Software Design. Question Topic Marks 1. Design Quality Design Patterns Design by Contract 12

Practice Problems. Review, with SOME solutions

Code Documentation.

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

MITOCW watch?v=yarwp7tntl4

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Reasoning About Imperative Programs. COS 441 Slides 10

MITOCW watch?v=tkwnms5irbu

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

The Challenge. Principles of Software Design

Starting to Program in C++ (Basics & I/O)

Functions in C C Programming and Software Tools

BCS Higher Education Qualifications. Diploma in IT. Object Oriented Programming Syllabus

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Let s start by recalling what a list is and considering the implementation we have already.

Analysis of the Test Driven Development by Example

6.170 Recitation #5: Subtypes and Inheritance

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

Software Engineering Testing and Debugging Testing

CSE 70 Final Exam Fall 2009

GRAPH ALGORITHMS Lecture 19 CS 2110 Spring 2019

Transcription:

Object design François Schwarzentruber ENS Cachan Antenne de Bretagne

Symptoms of rotting systems (according to Robert C. Martin) Four behaviors of the developer team: Rigidity Fragility Immobility Viscosity

Rigidity Could you please add the cancellation feature? Yes I will implement it

Rigidity

Rigidity I am sorry... it will take several months to do it! Ok... let us forget about it... This functionality will never be implemented.

Fragility Could you please add the cancellation feature? Yes I will implement it

Fragility

Fragility I have done it! 1) I completely changed the structure. 2) I implemented it... Oh my god... But you already changed 3 times the structure of the software for all the 3 features we have told about! The developer team is not to be trusted.

Immobility

Immobility >(+ 1 2) 3 I need a scheme evaluator... Oh! Here is a complete scheme library for JAVA. SchemeJ A complete scheme library for JAVA! Open source

Immobility I will try to find the scheme evaluator from it... SchemeJ A complete scheme library for JAVA! Open source

Immobility SchemeJ A complete scheme library for JAVA! Open source I do not understand anything I will write my own interpreter...

Viscosity

Viscosity from a MIT2 internship report...

SOLID 5 principles of object oriented class design Introduced by Robert C. Martin

S : Single responsibility principle There should never be more than one reason for a class to change. Class of a game : - that computes the position of enemies - that computes the score Change the gravity? Change the way of counting the score? Class of a game that uses two objects : - one that computes the position of enemies - another that computes the score

S : Single responsibility principle There should never be more than one reason for a class to change. I do gravity... After your modification, I modify the score definition. Or I implement both... Change the gravity? Change the way of counting the score? I modify GravityManager. I modify ScoreManager.

S : Single responsibility principle There should never be more than one reason for a class to change. I propose two gravity modes... Change the gravity? Change the way of counting the score? I propose two score modes...

O : Open Closed Principle Change the code source of module to add functionnality Being able to extend modules without changing the code source abstraction

O : Open Closed Principle Class Enemy { void move() { if(type == RABBIT)... else if(type == BROWSER)... else if(type == MUSHROOM)... } }

O : Open Closed Principle Class Enemy { void move() { if(type == RABBIT)... else if(type == BROWSER)... else if(type == MUSHROOM)... } For each change of } a type of enemy, I recompile all the class Enemy... Oh I just recompile one class...

O : Open Closed Principle Class Enemy { void move() { if(type == RABBIT)... else if(type == BROWSER)... else if(type == MUSHROOM)... } } void jump() { if(type == RABBIT)... else if(type == BROWSER)... else if(type == MUSHROOM)... }. If I add a new. type of enemy,. I check all the if/else statements... Oh I just add a new class...

L : Liskov Substitution Principle Barbara Liskov Turing award 2008

L : Liskov Substitution Principle

L : Liskov Substitution Principle But a circle is simplier... And we extend it to make a ellipse... It seems reasonable...

L : Liskov Substitution Principle Class Circle { public float getr(); public float getarea(); } Class Ellipse extends Circle {... } But a circle is simplier... And we extend it to make a ellipse... Circle c; c = new Ellipse(...); /* Here we expect that the area of c is c.getr()^2 * PI */

L : Liskov Substitution Principle and design by contract Class Ellipse { void setfocus(point p1, p2) { this.p1 = p1; this.p2 = p2; } : } Class Circle extends Ellipse { void setfocus(point p1, p2) { this.p1 = p1; this.p2 = p1; } : } : Ellipse e = new Circle(); e.setfocus(p1, p2); //and e is an ellipse!

L : Liskov Substitution Principle and design by contract Class Ellipse { postcondition: this.p1 == p1 & this.p2 == p2 void setfocus(point p1, p2) { this.p1 = p1; this.p2 = p2; } : } Class Circle extends Ellipse { void setfocus(point p1, p2) { this.p1 = p1; this.p2 = p1; } : } :! Ellipse e = new Circle(); e.setfocus(p1, p2); assert(e.getp1() == p1); assert(e.getp2() == p2);

L : Liskov Substitution Principle and design by contract Class Ellipse { invariant: inv } precondition: pre postcondition: pos void setfocus(point p1, p2) { } : Class Circle extends Ellipse { invariant: stronger than inv } precondition: weaker than pre postcondition: stronger than pos void setfocus(point p1, p2) { } :

I : Interface Segregation Principle I am plumber... I am plumber... I am an electrical fitter. I am an electrical fitter. Here is the entire map of the house. I propose an interface for accessing to pipes. I propose an interface for accessing to cables.

I : Interface Segregation Principle I am plumber... I am plumber... I am an electrical fitter. I am an electrical fitter. Here is the entire map of the house. I propose an interface for accessing to pipes. I do not understand. I propose an interface for accessing to cables. I understand better.

I : Interface Segregation Principle I am plumber... I am plumber... I am an electrical fitter. I am an electrical fitter. Here is the entire map of the house. I propose an interface for accessing to pipes. I changed the pipes... I changed the pipes... Oh no... I propose an interface for accessing to cables. I do not care.

D: Dependency Inversion Principle I make a web service for booking flights. Cool... I like flights. And what about trains? Oh no... I make a web service for booking abstract travels. I propose an interface that specifies what an abstract travel is. Ok... I will implement it for flights. Ok... I will implement it for trains. Oh yeah!

D: Dependency Inversion Principle Example: JAVA MidiSound MIDIPlayer I_Synthesizer Synthesizer

Principles of Package Architecture

Package Cohesion Principles

Remark We refactor the packages during the development: At the begining stage, we favor the developper. At the end, we favor the clients.

The Common Closure Principle Classes that change together, belong together. Good for the developper! Change!! And we need to change here too! Packages tend to be large.

The Release Reuse Equivalency Principle A package Good for the client! the granule of reuse The granule of release Number of versions Should support and maintain older versions Packages tend to be small.

The Common Reuse Principle Classes that aren t reused together should not be grouped together. Good for the client! Change!! Change!! client Oh no... you modify a class I don't care But I must still test my implementation that depends on your $%!$ package! client client Packages tend to be small.

The Package Coupling Principles.

The Acyclic Dependencies Principle The dependencies betwen packages must not form cycles. I work on Protocol... and I need to test my package with Comm Error.

The Acyclic Dependencies Principle The dependencies betwen packages must not form cycles. I work on Protocol... and I need to test my package with all the packages!

Solution: Dependency Inversion Principle

The Stable Dependencies Principle Depend in the direction of stability My work depends on package X! My work depends on package X! I need to modify X.. because it is related to other packages... because it is a difficult part of the project... Good point. X will not Change anymore. Oh no... X is not stable... X is stable!

Stable / instable Y instable X stable

The stable abstractions principle Stable packages should be abstract packages. Flexible / instable Stable

The stable abstractions principle Stable packages should be abstract packages. Flexible / instable Stable but we want them flexible should be abstract in order to be extended!

Dream 1: Automated assistance Software to help you to design the architecture warning: no abstract enough X

Measuring instability i i

Measuring abstractness

Instability VS Abstractness

The zone of pain Player Map Graphical library for Android 3.0

The main sequence Player Map General Graphical library

The zone of uselessness General Graphical library

Dream 2: creating automatically the packages partition

Dream 2: creating automatically the packages partition

Dream 2: creating automatically the packages partition A new field [Mitchell 2002] Bunch [Mitchell et al. 2006] Nothing about stability and abstractness Preliminary work...

Related problems P: Minimal cut by flow algorithms = finding two packages with low coupling NP: Graph partitioning (minimal cut plus a constraint over the size of the packages) = finding two `big' packages with low coupling The clique problem, NP-complete = find a package with high cohesion

Mitchell's PhD Measuring cohesion Measuring coupling Measuring the quality of a clustering

Heuristics Hill-climbing algorithms Genetic algorithms PS : People claim the problem is NP-complete (I want a proof)