CSHenrik Bærbak Christensen1 Flexibility and Maintainability And their metrics: coupling and cohesion.

Slides:



Advertisements
Similar presentations
Software Engineering Key design concepts Design heuristics Design practices.
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
DAIMIHenrik Bærbak Christensen1 What is Software Quality?
CS350/550 Software Engineering Lecture 1. Class Work The main part of the class is a practical software engineering project, in teams of 3-5 people There.
Low Coupling High Cohesion
Object-Orientated Design Unit 3: Objects and Classes Jin Sa.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Computer Science 240 Principles of Software Design.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CS 4240: The OO Paradigm Revisited Readings: Chap. 1 of Design Patterns Explained OO (some review) Coupling, cohesion.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
Design Patterns.
Objects and Components. The adaptive organization The competitive environment of businesses continuously changing, and the pace of that change is increasing.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
CSE 303 – Software Design and Architecture
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
Architecture GRASP Realization of use cases in interaction diagrams Design class diagram Design ( how )
Design Patterns. Patterns “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
SE: CHAPTER 7 Writing The Program
Cohesion and Coupling CS 4311
Object-Oriented Analysis and Design Fall 2009.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Chapter 7 Software Engineering Introduction to CS 1 st Semester, 2015 Sanghyun Park.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 13 Creational Design Pattern SWE 316: Software Design and Architecture.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Introduction to Software Architecture.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
1 OO Analysis & Design - Introduction to main ideas in OO Analysis & design - Practical experience in applying ideas.
Chapter 2 Object-Oriented Paradigm Overview. Getting Acquainted with the Class Project Read the requirements specification carefully Make note of any.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Design and Planning Or: What’s the next thing we should do for our project?
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Design. Practices Principles Patterns What are the characteristics of good design? What are good solutions to common design problems? How do we go about.
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
1 Here are some quotations to get an overview of the kinds of issues of interest.
Multi Dimensional Variance: How to make ultra flexible software!
Applying the Principles Two Examples. Example 1 New Requirement It would be nice with a simple GUI “to see something” instead of just xUnit tests...
Refactoring and Integration Testing or Strategy, introduced reliably by TDD The power of automated tests.
MiniDraw Introducing a Framework... and a few patterns.
Software Architecture Quality Attributes. Good or Bad? Measurable criterions required...
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Strategy in 15 minutes... derived from the principles.
CS 350 – Software Design The Facade Pattern – Chapter 6 Many design patterns are catalogued in the “Gang of Four” text. I find their definitions not to.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Mantas Radzevičius ifm-2/2
Applying the Principles
Chapter 11 Object-Oriented Design
Copyright © by Curt Hill
TK2023 Object-Oriented Software Engineering
Objects First with Java A Practical Introduction using BlueJ
Chapter 5 Designing the Architecture Shari L. Pfleeger Joanne M. Atlee
Design Tips.
An Introduction to Software Architecture
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ
Software Engineering and Architecture
Presentation transcript:

CSHenrik Bærbak Christensen1 Flexibility and Maintainability And their metrics: coupling and cohesion

What is this? So – all you smart guys and girls – what is this? What does it do? What every-day abstraction is this code implementing? (Note: the code fragment in the book is incorrect  ) CSHenrik Bærbak Christensen2

The point The customers / executing software do not care if the code is –Readable / understandable / well documented As long as it serves its purpose well... However, developers do –Unless you are about to quit tomorrow –Or in a consulting company CSHenrik Bærbak Christensen3

What developers want... We need software to be maintainable Maintainability is a quality that our code has to a varying degree –Low maintainability -> high maintainability CSHenrik Bærbak Christensen4

Aspects Maintainability is influenced by a lot of sub qualities. CSHenrik Bærbak Christensen5

Analyzability Basically: can I understand the code? –Indentation –Intention-revealing names of methods –Follow language conventions –Useful comments and JavaDoc –Training! To spot e.g. Design Patterns CSHenrik Bærbak Christensen6

Changeability Cost of modifying the code –160x45 maze? CSHenrik Bærbak Christensen7

Stability In BASIC all variables are global –do not store some global property in variable i ! Why not? CSHenrik Bærbak Christensen8

Testability Everything can be tested – right? Ariane rocket guidance system bug –Found when they launched it... –Overflow error due to 64-bit to 16-bit conversion CSHenrik Bærbak Christensen9

Flexibility A main theme of FRS ! Change by addition, not by modification... CSHenrik Bærbak Christensen10

Coupling and Cohesion Two metrics highly correlating to maintainability of software CSHenrik Bærbak Christensen11

CSHenrik Bærbak Christensen12 To measure software Programmers with some experience has a sense of good and bad software. Some of the ”heavy guys” like Kent Beck and Martin Fowler also talks about code smell. But... what is good and what is bad? Not very scientific anyway It is better to measure software according to some defined metric.

CSHenrik Bærbak Christensen13 Examples of metrics A very simple, widely used, and next to useless metric is kloc = Kilo Lines of Code. It simply measures the quantity of code. Useless? –Is 2kloc better than 1kloc?

CSHenrik Bærbak Christensen14 A maintainability measure Coupling (da: kobling): unit = a well delimited unit of code: class, package, module, method, application, etc. Low coupling: few dependencies Tight coupling: lot of dependencies

CSHenrik Bærbak Christensen15 Example

CSHenrik Bærbak Christensen16 Exercise Name some language constructs or techniques that generate dependencies between two classes. ?

CSHenrik Bærbak Christensen17 War story In the ABC research project, a knowledge based system was able to guess at human activities based on knowledge of location of objects in a hospital setting. For instance co-location of a medicine tray, a nurse and a patient would trigger a ”the patient is receiving medicine” activity proposal. The ID used in the knowledgebase was RFID tag ID. Later, some programmer changed ID for persons to CPR identity instead.

CSHenrik Bærbak Christensen18 Rule of Thumb: Not that surprising: Assign responsibility so coupling is low Because –Local change has no/less impact –Easier to understand modules in isolation –Higher probability of reuse with few dependencies

CSHenrik Bærbak Christensen19 Cohesion Cohesion (da: kohæsion/binding/samhørighed): Example: –Unit X: all classes that begin with letters A, B, and C –Unit Y: all classes related to booking a flight seat

CSHenrik Bærbak Christensen20 Rule of Thumb Also not surprising: Assign responsibility so cohesion is high

CSHenrik Bærbak Christensen21 Discussion Maintainable software generally has weak coupling and high cohesion. Weak coupling means one change does not influence all other parts of the software –lowering cost of change High cohesion means that a change is likely localized in a single subsystem, easier to spot –lowing the cost of change

CSHenrik Bærbak Christensen22 Law of Demeter A very concrete “law” that addresses the coupling measure is Law of Demeter: Do not collaborate with indirect objects Also known as Don’t Talk to Strangers Example p.getX().getY().getZ().fecthA().doSomething();

CSHenrik Bærbak Christensen23 Lieberherr Within a method, messages should only be sent to –this –a parameter of the method –an attribute of this –an element of a collection which is an attribute of this –an object created within the method In other words: “never two dot’s in a call”

CSHenrik Bærbak Christensen24 War story Major Danish IT company –problem: dynamic configuration of user interface elements –solution: configuration parameters in property file read at run-time if ( dialogX.panelY.listboxZ.color == NONE ) {...} – 

CSHenrik Bærbak Christensen25 Then what? Rule of Thumb: –Assign the responsibility to the client’s direct object to do the collaboration with indirect objects Thus –order.getItem(3).getPrice().addTax() –should be replaced by –order.addTaxToItem(3); Liabilities?

CSHenrik Bærbak Christensen26 Then what? Exercise: –Do we see this in the pay station? –In HotGammon/HotCiv? Consequences – Law of Demeter lowers direct coupling –  Interfaces may bloat with too many method