1 Software Maintenance and Evolution CSSE 575: Session 6, Part 3 Problems with Changing Software - 2 Steve Chenoweth Office Phone: (812) 877-8974 Cell:

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
Advertisements

1 Software Maintenance and Evolution CSSE 575: Session 2, Part 3 Moving Features Between Objects Steve Chenoweth Office Phone: (812) Cell: (937)
1 Software Maintenance and Evolution CSSE 575: Session 6, Part 1 The “SEAM” Model Steve Chenoweth Office Phone: (812) Cell: (937)
1 Software Maintenance and Evolution CSSE 575: Session 6, Part 4 Breaking Dependencies Steve Chenoweth Office Phone: (812) Cell: (937)
1 Software Maintenance and Evolution CSSE 575: Session 8, Part 3 Predicting Bugs Steve Chenoweth Office Phone: (812) Cell: (937)
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
Loops Notes adapted from Dr. Flores. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while”
1 CS2200 Software Development Lecture 29: Polymorphism I A. O’Riordan, 2008 Based on notes by K. Brown.
CPSC150 Abstract Classes and Interfaces Chapter 10.
CPSC150 Abstract Classes Chapter 10. CPSC150 Directory Example (note: your assignment does not have all of this) DirectoryEntry name phone public void.
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
Programming with Collections Grouping & Looping - Collections and Iteration Week 7.
OOP Week 3 1 Object Oriented Programming in Java Monday, Week 3 Interface PinBallTarget OOP Concepts Last Week’s Assignment Arrays Collection Class --
Abstract Classes and Interfaces
CSSE 374: More GRASP’ing and Use Case Realization Steve Chenoweth Office: Moench Room F220 Phone: (812) These.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
1 Software Maintenance and Evolution CSSE 575: Session 6, Part 2 Problems with Changing Software - 1 Steve Chenoweth Office Phone: (812) Cell:
Packages. Package A package is a set of related classes Syntax to put a class into a package: package ; public class { …} Two rules:  A package declaration.
Chapter 3 Vector Class. Agenda Design and Implementation of Vector class – add, get, set remove, copy, equals, ensureCapacity Hangman using Vector class.
1 CSSE 375 – Software Construction & Evolution Problems with Changing Software - 2 Steve Chenoweth, RHIT Below – How do you know if your unit test really.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
CSE 143 Lecture 20 Binary Search Trees continued; Tree Sets read slides created by Marty Stepp and Hélène Martin
Working Effectively with Legacy Code
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Chapter 9: The Iterator Pattern
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 1 Simplifying Conditionals Steve Chenoweth Office Phone: (812) Cell: (937)
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
JAVA COLLECTIONS M. TAIMOOR KHAN (ADAPTED FROM SWINBURNE NOTES)
Session 19 Chapter 10 – Mechanisms for Software Reuse.
Session 18 Chapter 8: Understanding Inheritance. Recall Exercise 2 From Tuesday It’s very annoying to move a target from the pallet and drop it in the.
Quizard step-by-step. Start with the questions The Question class is abstract –a Superclass You’ll never create something that’s just a question. It’ll.
QUEUES What are Queues? Creating a Queue Enqueuing and Dequeuing Testing for an Empty Queue.
Inheritance Notes Chapter 6 1. Inheritance  you know a lot about an object by knowing its class  for example what is a Komondor? 2
1 Software Construction and Evolution - CSSE 375 Exception Handling – Chaining & Threading Steve Chenoweth Office: Moench Room F220 Phone: (812)
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Creating a GUI Class An example of class design using inheritance and interfaces.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Software Construction and Evolution - CSSE 375 Dealing with Generalization Steve and Shawn Left – In the 1990 movie “The Freshman,” Matthew Broderick,
Collections and Iteration Week 13.  Collections  ArrayList objects  Using loops with collections Collections and Iteration CONCEPTS COVERED THIS WEEK.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
Observer Pattern Context:
CSE 143 Lecture 20 Binary Search Trees continued; Tree Sets
slides created by Marty Stepp
slides created by Marty Stepp and Ethan Apter
slides created by Marty Stepp and Hélène Martin
CSE 303 Concepts and Tools for Software Development
Binary Search Trees continued; Tree Sets
slides adapted from Marty Stepp
Building Java Programs
Presentation transcript:

1 Software Maintenance and Evolution CSSE 575: Session 6, Part 3 Problems with Changing Software - 2 Steve Chenoweth Office Phone: (812) Cell: (937) hulman.eduz Below – How do you know if your unit test really tested the important things? Did you use representative data? Does it predict success in integration testing? Cartoon from 27/national-standards-are-they-necessary- guest-blog/. 27/national-standards-are-they-necessary- guest-blog/

2 A few more cool examples…Ch 10 “I can’t run this method in a test harness.” Reasons could include: – Method not acccessible to the test – Hard to construct the parameters to call a method – Method has bad side effects, like modifying a database or launching a cruise missile – Need to “sense through” some object that the method uses

3 Testing a private method Feathers’ opening comments: Private methods tend to be of dubious quality. They often look very general, but really work only for the things in their class that use them. Making them public opens a can of worms!

4 Private methods, cntd Thus, these represent things that are inherently not testable – questionable design. His example (in C++): class CCAImage { private: void setSnapRegion(int x, int y, ind dx, int dy); … public: void snap(); … };

5 Private methods, cntd Feathers’ solution: Make the private class protected instead of private. Then delegate to a testing subclass: class TestingCCAImage : public CCAImage { public: void setSnapRegion(int x, int y, ind dx, int dy) { // call the setSnapRegion of the superclass CCAImage::setSnapRegion(x, y, dx, dy) } };

6 Undetectable side effects Feathers’ example – a class that calls methods on other objects, and we never have a clue how things turn out: Public class AccountDetailFrame extends Frame implements ActionListener, WindowListener { private TextField display = new TextField(10); … public AccountDetailFrame(…) {…} public void actionPerformed(ActionEvent event) { String source = (String)event.getActionCommand(); if (source.equals(“project activity”)){ DetailFrame detailDisplay = new DetailFrame(); detailDisplay.setDescription( getDetailText() + “ “ + getProjectionText()); detailDisplay.show(); String accountDescription = detailDisplay.getAccountSymbol(); accountDescription += “: “; … display.setText(accountDescription); … } … }

7 Undetectable side effects, cntd Feathers’ solution – separate dependencies, including using Bertrand Meyer’s Command / Query separation principle Part 1: Public class AccountDetailFrame extends Frame implements ActionListener, WindowListener { private TextField display = new TextField(10); private DetailFrame detailDisplay ; … public AccountDetailFrame(…) {…} public void actionPerformed(ActionEvent event) { String source = (String)event.getActionCommand(); performCommand(source); } public void performCommand(String source){ if (source.equals(“project activity)){ setDescription(getDetailText() + “ “ + getProjectionText()); … String accountDescription = detailDisplay.getAccountSymbol(); accountDescription += “: “; … setDisplayText(accountDescription); } }cntd  Bertrand Meyer – Also author of the Eiffel programming language and of “design by contract” programming.

8 Undetectable side effects, cntd Feathers’ solution – separate dependencies, including using Bertrand Meyer’s Command / Query separation principle Part 2: … void setDescription(String description){ detailDisplay = new DetailFrame(); detailDisplay.setDescription(description); detailDisplay.show(); } String getAccountSymbol(){ return detailDisplay.getAccountSymbol(); } void setDisplayText(String description){ display.setText(accountDescription); } … }

9 Undetectable side effects, cntd We can now subclass and override to test whatever code is left in performCommand: public class TestingAccountDetailFrame extends AccountDetailFrame { String displayText = ““; String accountSymbol = “”; void setDescription(String description{ } String getAccountSymbol(){ return accountSymbol; } void setDisplayText (String text){ displayText = text; }

10 Undetectable side effects, cntd And a test exercise on the performCommand method would look like this: public void testPerformCommand(){ TestingAccountDetailFrame frame = new TestingAccountDetailFrame(); frame.accountSymbol = “SYM”; frame.performCommand(“project activity”); assertEquals(“SYM: basic account”, frame.displayText); }

11 Another cool example…Ch 11 Impact analysis during maintenance – Feathers’ dream tool – he highlights code in the IDE, and it tells him everything impacted if he changes that code! Need to reason backward and forward about changes – Backward = deduce the set of objects that affect values at a particular point in code. – Forward = look at a set of objects and determine what will change downstream if they stop working.

12 Reasoning forward example We want to make changes to this code, to allow the index to change as items are added to the ArrayList: import java.util.ArrayList; import java.util.Iterator; /** chenowet. * Created Jul 12, */ public class InMemoryDirectory { private ArrayList elements = new ArrayList(); public void addElement(Element newElement){ elements.add(newElement); } public int getElementCount(){ return elements.size(); } public Element generateIndex() { Element index = new Element("index"); for(Iterator it = elements.iterator(); it.hasNext();){ Element current = (Element)it.next(); index.addText(current.getName()+"\n"); } addElement(index); return index; } public Element getElement(String name){ for (Iterator it = elements.iterator(); it.hasNext();){ Element current = (Element)it.next(); if (current.getName().equals(name)) { return current; } return null; } This is what generates index now!

13 Reasoning forward example, cntd Issues: Need to generate the index last -- it doesn’t work if rebuilt. But this was ok in the existing app. Now, we’d like index creation and maintenance to happen automatically as a side effect of adding elements. How to test as we develop this change?

14 Reasoning forward example, cntd So we need tests that: Add elements in various ways, Generate an index, Get the various elements and see if they are correct, and Test to see if the index is correct. How do we know this is the extent of the testing needed?

15 Reasoning forward example, cntd The tests are just a description of how we expect to use the directory (and revisions to the add function). We know what the directory is supposed to do. But, could we have known this just by looking at the code itself?

16 Reasoning forward example, cntd Our goal is to remove functionality from generateIndex and add it to addElement. So, – What calls generateIndex? Nothing in the class itself. So it must just be client classes. – What do we modify in generateIndex? We create a new element (the index) and add it to the ArrayList (the directory). Thus, this method affects the elements in the list. …But we’re not done!

17 Reasoning forward example, cntd Where else is the elements collection used? – Used in getElementCount and in getElement. – Used in addElement, but we don’t care!

18 Reasoning forward example, cntd Also need to look at how addElement impacts the surrounding software: – It affects the elements collection. …But we’re not done!

19 Reasoning forward example, cntd As before, we also need to see what the elements collection itself can affect, giving this overall picture:

20 Reasoning forward example, cntd Could we have missed anything? – Superclasses and subclasses? – Is the data in InMemoryDirectory public? Not in this case! – What about the elements themselves?

21 Reasoning forward example, cntd /** chenowet. * Created Jul 12, */ public class Element { private String name; private String text; public Element(String name){ this.name = name; this.text = ""; } public String getName(){ return this.name; } public void addText(String newText){ this.text = this.text + newText; } public String getText(){ return this.text; }

22 Reasoning forward example, cntd So, overall, the impacts are:

23 Reasoning forward example, cntd Heuristics for analyzing effects propagation: Look for methods returning values – Assuming these are used! An object that takes another object as a parameter – Can change that object! – Depends on the language Other side effects like – Changing global or static data