MSO Lecture 9. Wouter Swierstra (adapted by HP, AL) October 12, 2017

Size: px
Start display at page:

Download "MSO Lecture 9. Wouter Swierstra (adapted by HP, AL) October 12, 2017"

Transcription

1 1 MSO Lecture 9 Wouter Swierstra (adapted by HP, AL) October 12, 2017

2 2 BEFORE WE START... Some notes on Kahoot! nicknames: Normaal: Anneke, Bastiaan, Pieter, Sjaak, Ruud,... Funny: Jeroen Fokker, Sergey Sosnovsky, Mark Rutte, Angela Merkel, Edsger Dijkstra, NL naar WK, smiley faces,... Maybe funny: Bier, Flammenwerfer, Himmler, Panzerkampfwagen, Reichsführer SS,... Not funny: sexist, racist, offensive and other sorts of inappropriate stuff that I am not going to repeat

3 3 LAST LECTURE Design by contract How can we ensure our code is correct?

4 4 THIS LECTURE What is refactoring? What are unit tests?

5 5 APPLYING DESIGN PATTERNS So far, we have often considered the situation where we can start designing new software from scratch. In practice, this is uncommon you usually have to develop with existing systems. Does that mean that design patterns are not useful in practice?

6 6 ITERATIVELY IMPROVING DESIGNS You can still apply design patterns to existing software: to improve the internal structure; to facilitate testing; to pave the way for new features.

7 Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behaviour. 7

8 8 CASE STUDY: REFACTORING A MOVIE RENTAL SYSTEM I want to cover a refactoring case study taken from the first chapter of Fowler s book. Starting with some poorly designed code, we will refactor this step by step.

9 9 STARTING SITUATION Customer statement() 1 * Rental daysrented:int * 1 Movie pricecode : int title : string

10 10 INITIAL CLASSES The Movie class defines three price codes as integer constants: CHILDREN = 0 STANDARD = 1 NEW = 2 The Rental class tracks the number of days a particular movie has been rented. Finally, the Customer class records a list of Rentals.

11 Question: What is wrong with 11 this code? STATEMENT COMPUTATION foreach (Rental v in rentals) { v_price = 0; switch (v.getmovie().getpricecode()) { case Movie.STANDARD : v_price = 3 euro * v.daysrented; break; case Movie.NEW : v_price = 5 euro * v.daysrented; break; case Movie.CHILDREN : v_price = 2 euro * v.daysrented; break; } totprice += v_price; pts++; if (v.getmovie().getpricecode()==movie.new); pts++; }

12 12 WEAK COHESION This fragment is computing the price of the rental and the customer points earned let s extract this into two separate methods.

13 13 EXTRACT METHOD foreach (Rental v in rentals) { v_price = calculateprice (v); totprice += v_price; pts++; if (v.getmovie().getpricecode()==movie.new) { pts++ }...

14 14 EXTRACT METHOD foreach (Rental v in rentals) { v_price = calculateprice(v); totprice += v_price pts = calculateearnedpoints(v,pts)... Note that we have to pass along enough information to compute the new running total of earned points in this example, we pass both the video v and current total points pts. But we can do even better...

15 15 GETTING RID OF TEMPORARY VARIABLES foreach (Rental v in rentals) { totprice += calculateprice(v); pts += calculateearnedpoints(v);... But should both these computations really be in the same loop? Wouldn t it be better to define separate getcharge() and getrenterpoints() methods?

16 16 GETTING RID OF SWITCHES switch (v.getmovie().getpricecode()) { case Movie.STANDARD : v_price = 3 euro * v.daysrented; break; case Movie.NEW : v_price = 5 euro * v.daysrented; break; case Movie.CHILDREN : v_price = 2 euro * v.daysrented; break; } Switches may cause maintenance headaches!

17 17 INHERITANCE We could define an abstract Movie class, with three subclasses but it would be even better to apply the Strategy pattern. Client Context Strategy computation(...) ConcreteStrategyA computation(..) ConcreteStrategyB computation(..) ConcreteStrategyC computation(..)

18 18 REFACTORING SAFELY It is all to easy to make mistakes or introduce bugs during refactoring. Big refactorings can be really complex. Question: What best practices can help refactor effectively?

19 19 REFACTORING Do not start refactoring complex code unless you have a good test suite how else will you know that refactoring hasn t changed a program s behaviour? Refactor in the smallest possible steps. Test after every step catching bugs earlier will make your life a lot easier.

20 20 WHY REFACTOR? Refactoring may be necessary to improve the software s design eliminating duplicate code, for example. Refactoring makes software easier to understand. Refactoring helps spotting bugs. Refactoring helps program faster.

21 21 WHEN SHOULD YOU REFACTOR? Rule of three. The first time you write something, just write it. The second time, wince at duplicate code. The third time, refactor. Refactor when you add a new feature. Refactor when you fix a bug. Refactor when you do a code review. There s no golden rule.

22 22 BAD CODE SMELLS Fowler identifies a list of bad code smells. These are not bugs, but symptoms in the source code that may indicate bad design, or the need for refactoring. Whenever you are programming, or doing a code review, knowing about bad code smells can help identify problems, before they become hard to fix. I ll try to cover a few here and give some examples.

23 23 BAD SMELL? temp_c1 = (5/9)*(temp_f1-32); temp_c2 = (5/9)*(temp_f2-32); temp_c3 = (5/9)*(temp_f3-32); avg_temp_c = (temp_c1 + temp_c2 + temp_c3) / 3;

24 24 DUPLICATED CODE temp_c1 = (5/9)*(temp_f1-32); temp_c2 = (5/9)*(temp_f2-32); temp_c3 = (5/9)*(temp_f3-32); avg_temp_c = (temp_c1 + temp_c2 + temp_c3) / 3; Remedy: introduce a method.

25 25 LONG METHOD int doit() {... // 500 lines of weakly cohesive gibberish... } This usually indicates on method is doing too much making it weakly cohesive (and hard to understand). Remedy: split into smaller, more cohesive methods.

26 26 LARGE CLASS public class TheSystem... // 1000 weakly cohesive methods... This indicates a class is doing too much making it weakly cohesive (and hard to understand). Remedy: split into smaller, more cohesive, loosely coupled classes. Besides code length, unspecific name choices for classes and methods may indicate bad smells.

27 27 TOO MANY PARAMETERS Result computeresult(databaseconnection db, UserQuery uq, ReceiptPrinter r, UserName name, CustomerReceiptHandler crh, SalesRegister register, CurrencyConverter cc, MovieDatabase mdb, CustomerIdNumber cin,...) This usually indicates that a method is trying to do too much weak cohesion!

28 28 ANTI-PATTERN: SHOTGUN SURGERY Suppose you want to make a change, for example, introduce a new kind of movie to the video store case study. But to do this, you need to update the existing software in many different places this is called shotgun surgery. If this is not an unusual modification, the software is poorly designed.

29 29 DIVERGENT CHANGE Suppose we have our Shapes in the CAD/CAM software again. Over time, we add colours to our Shapes, methods for modifying colours (increasing transparency, brightness, etc.). But we also add information about borders maybe sometimes the border should be dashed or dotted. As time goes on, each individual Shape object is less and less cohesive. Remedy: Introduce separate classes to handle colours and borders.

30 30 BAD SMELL? switch (v.getmovie().getpricecode()) { case Movie.STANDARD : v_price = 3 euro * v.daysrented; break; case Movie.NEW : v_price = 5 euro * v.daysrented; break; case Movie.CHILDREN : v_price = 2 euro * v.daysrented; break; }

31 31 SWITCH STATEMENTS switch (v.getmovie().getpricecode()) { case Movie.STANDARD : v_price = 3 euro * v.daysrented; break case Movie.NEW : v_price = 5 euro * v.daysrented; break case Movie.CHILDREN : v_price = 2 euro * v.daysrented } The responsibility for this computation is in the wrong place. Remedy: Add a method to the superclass (or introduce a Strategy).

32 32 COMMENTS Comments are a Good Thing, right? This should be a sweet smell, not a bad smell...

33 33 COMMENTS But if a method or objects needs lots of comments, maybe these comments are masking bad design. public void compute() { \\ This is a really complicated method \\ that shouldn't be changed. \\ It took me a long time to get right, \\ so DO NOT TOUCH IT!!!!!

34 34 BAD NAMES Excessively long identifiers: in particular, the use of naming conventions to provide disambiguation that should be implicit in the software architecture. SystemControllerHandlerFactoryComponent Excessively short identifiers: the name of a variable should reflect its function unless the function is obvious. z = h.getx() * i.gety() + k.getq(); Excessive use of literals: x = 3.14 * / 256;

35 35 FOWLER S REFACTORING CATALOGUE Every refactoring is described in a uniform format: The refactoring s name; A summary of what the refactoring does; The motivation explaining when to apply the refactoring (and when not to apply it). The mechanics giving a recipe of how to apply a refactoring. Finally, examples illustrating a refactoring.

36 36 EXAMPLE: INLINE TEMP Summary: You have a temporary variable that is assigned to once with a simple expression, and the temp is getting in the way of other refactorings. Replace all references to that temp with the expression. double baseprice = anorder.baseprice(); return (baseprice > 1000) Becomes: return (anorder.baseprice() > 1000);

37 37 EXAMPLE: INLINE TEMP Mechanics 1. Declare the temp as a constant and compile. This tests that it is really only assigned once. 2. Find all references to the temp and replace them with the right-hand side of the assignment. 3. Compile and test after each change. 4. Remove the declaration of the assignment of the temp. 5. Compile and test.

38 38 EXAMPLE: INLINE TEMP Motivation: (fragment from Fowler) The only time Inline Temp is used on its own is if you find a temp that is assigned the value of a method call. Often the temp isn t doing any harm and you can leave it there. If the temp is getting in the way of other refactorings, such as Extract Method, it s time to inline it.

39 39 INVERSES Many refactorings have a reverse refactoring as well. For example, Introduce explaining variable is the opposite of Inline temp. // base price - quantity discount + shipping return quantity * itemprice - Math.max(0, quantity - 500) * itemprice * Math.min(quantity * itemprice * 0.1, 100); Becomes: double baseprice = quantity * itemprice; double discount =... double shippingfee =... return baseprice - discount + shippingfee;

40 REFACTORING WITH VISUAL STUDIO 40

41 41 Finally, I want to give a quick overview of some other refactorings that Fowler identifies: Introduce parameter object Moving methods, fields, or attributes. Splitting classes Hiding delegates You might argue that these refactorings are on the level of design rather than code.

42 42 INTRODUCE PARAMETER OBJECT Methods with too many parameters are hard to call: processcustomerondate(date, isopen, age, hasdiscountcard, customerid) Perhaps it is better to reorganize this into: processcustomerondat(dateprofile, customerprofile) and introduce new objects dateprofile and customerprofile storing the associated data.

43 43 MOVING CODE Person name age street zipcode city housenumber... printaddress() Perhaps this class is becoming too weakly cohesive...

44 This is an example of the Extract class refactoring. 44 MOVING CODE Person name age address Address street zipcode city housenumber... printaddress()

45 45 Product name : String Coffee discount() Apple discount() If all subclasses support the discount method, shouldn t this be defined in the superclass?

46 46 Product name : String discount() Coffee Apple This is the Pull-up refactoring.

47 47 Product name : String drink() Coffee Apple Why should you define a dummy implementation for the drink method of the Apple class?

48 48 Product name : String Coffee drink() Apple It s better to apply the Pull-down refactoring.

49 49 REFACTORINGS IN ALL SHAPES AND SIZES There are lots of other kinds of refactorings: Extract a common superclass when several classes share the same attributes and methods; Introduce a new subclass of X, to distinguish a specific kind of X. Replace inheritance with delegation and visa versa....

50 50 REFACTORING LESSONS Refactoring helps keep code clean. Aim for self-documenting code: choose meaningful names; lift complex computations into separate methods; keep control flow simple;... When refactoring, take small steps and test all the time.

51 Software testing 51

52 Why test software? 52

53 53 WHY TEST SOFTWARE? Test software to try and break things to find bugs. Test that your software has been installed correctly. Test that code changes (new features or bug fixes) do not introduce new bugs. Test performance, security, usability, accessibility, or any non-functional requirements....

54 54 WHAT TO TEST? Acceptance testing test that the user accepts the final product; System testing test an entire system, before handing it over to end users; Integration testing test that different software components (that may have been tested individually) work together; Regression testing tests that run nightly to check for new bugs; Unit testing testing individual software units.

55 55 UNIT TESTING Unit testing is a method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine if they are fit for use.

56 56 UNIT TESTING Test one unit at a time; Don t test code that will not break, like getters and setters focus on the difficult parts. Tests are code too. Choose meaningful names (testsuccessfultransfer rather than test3); Avoid repetition; Organize tests, just as you would organize other code.

57 57 EXAMPLE: TESTING BANK ACCOUNT SOFTWARE BankAccount - customername : string - balance : double - isfrozen : bool + Debit(amount) + Credit(amount) + FreezeAccount() + UnfreezeAccount()

58 58 DEBIT IMPLEMENTATION public void Debit(double amount) { if (isfrozen) { throw new Exception("Account frozen"); } if (amount > balance amount < 0) { throw new ArgumentOutOfRangeException("amount"); } balance -= amount; }

59 59 CREDIT IMPLEMENTATION public void Credit(double amount) { if (isfrozen) { throw new Exception("Account frozen"); } if (amount < 0) { throw new ArgumentOutOfRangeException("amount"); } } balance += amount;

60 60 TESTING... Test that tricky functions compute the right thing but also test that exceptional cases get triggered! Tests are typically written using assertions. An assertion is passed a boolean expression; If the expression evaluates to True, nothing happens and the test passes; otherwise the assertion throws an error, and possibly reports debugging information.

61 A FIRST UNIT TEST public void DebitWithValidAmount() { double beginningbalance = 11.99; double debitamount = 4.55; double expected = 7.44; BankAccount account = new BankAccount("Mr. Walter White", beginningbalance); // act account.debit(debitamount); } // assert double actual = account.balance; Assert.AreEqual(expected, actual, 0.001); 61

62 public void DebitTriggerException { double beginningbalance = 11.99; double debitamount = 20.0; BankAccount account = new BankAccount("Mr. Walter White", beginningbalance); try { account.debit(debitamount); } catch (ArgumentOutOfRangeException e) { StringAssert.Contains(e.Message, "amount"); return; } Assert.Fail("No exception was thrown.") } 62

63 63 WHAT S MISSING? How would you check that no transactions can be done on frozen accounts? What other cases are missing? Is it good to have a the String Amount in both the test code and the original class? What about having duplicate setup code in every test?

64 HOW TO TEST? The Assert class has a long list of basic assertions: compare two primitive types for equality; assert that a boolean must be true; check that an object is not null; fail; inconclusive. The CollectionAssert class provides various assertions about generic collections. The StringAssert class provides assertions related to strings: Contains(String,String) StartsWith(String,String) EndsWith(String,String) Matches(String,Regex) Various exception classes for when an assertion fails, when a test fails, when a test expects an exception to be thrown, etc. 64

65 65 TESTING IN VISUAL STUDIO There is pretty good unit test support in Visual Studio. You can generate a unit test framework for a class with a few clicks; Automated tools for running tests and showing code coverage; Help in writing stubs/mock classes; And lots more...

66 66 UNIT TESTING COMPLEX SYSTEMS Suppose you need to test a complex system that interacts with a database. Querying the database takes a long time and is complex to set up. Besides, I don t want my tests to corrupt my data. How do I write unit tests?

67 67 STUBS, FAKES, AND MOCKS Stub objects always return the same response; Every database query returns the same result. Fake objects behave correctly, but have a simplistic implementation; A fake database object has a list of data base entries stored as a C# list. Mock objects also test that its calls satisfy constraints. The mock database knows about the database schema and also tests that queries are valid.

68 68 UNIT TESTING: BEST PRACTICES 1. Make sure your tests test one thing and one thing only. 2. Write unit tests as you go. Preferably before you write the code you are testing against. 3. Do not unit test the GUI. 4. Separate your concerns. 5. Minimise the dependencies of your tests. 6. Mock behaviour with mocks.

69 69 TEST-DRIVEN DEVELOPMENT With the rise of Agile methodologies, Test-driven development has gained a lot of traction in the past years. 1. Start the iteration by writing tests. 2. Add code that makes the tests pass. 3. Refactor your solution. Sometimes summarized as red-green-refactor. Question: What might the benefits of this approach be?

70 70 BENEFITS OF TDD It forces developers to think about specifications first. Strongly coupled or weakly cohesive code is hard to test. Writing tests first encourages better design. Tests are not an afterthought. The end of the iteration may encourage developers to skimp on writing tests. Machine-checked documentation for free Code is more robust against refactoring later.

71 71 MATERIAL COVERED Refactoring. Martin Fowler. Verifying Code by Using Unit Tests. MSDN. Available online.

MSO Refactoring. Hans Philippi. October 2, Refactoring 1 / 49

MSO Refactoring. Hans Philippi. October 2, Refactoring 1 / 49 MSO Refactoring Hans Philippi October 2, 2018 Refactoring 1 / 49 This lecture What is refactoring?... or how to deal with the horrible code your colleagues have created... or how to deal with the horrible

More information

MSO Lecture 6. Wouter Swierstra. September 24, 2015

MSO Lecture 6. Wouter Swierstra. September 24, 2015 1 MSO Lecture 6 Wouter Swierstra September 24, 2015 2 LAST LECTURE Case study: CAD/CAM system What are design patterns? Why are they important? What are the Facade and Adapter patterns? 3 THIS LECTURE

More information

MSO Lecture 6. Wouter Swierstra (adapted by HP) September 28, 2017

MSO Lecture 6. Wouter Swierstra (adapted by HP) September 28, 2017 1 MSO Lecture 6 Wouter Swierstra (adapted by HP) September 28, 2017 2 LAST LECTURE Case study: CAD/CAM system What are design patterns? Why are they important? What are the Facade and Adapter patterns?

More information

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture Credit where Credit is Due Lecture 25: Refactoring Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some of the material for this lecture and lecture 26 is taken

More information

Administrivia. Programming Language Fall Example. Evolving Software. Project 3 coming out Midterm October 28. Refactoring October 14, 2004

Administrivia. Programming Language Fall Example. Evolving Software. Project 3 coming out Midterm October 28. Refactoring October 14, 2004 CMSC 433 Programming Language Fall 2004 Project 3 coming out Midterm October 28 Administrivia Refactoring October 14, 2004 Lots of material taken from Fowler, Refactoring: Improving the Design of Existing

More information

Evolving Software. CMSC 433 Programming Language Technologies and Paradigms Spring Example. Some Motivations for This Refactoring

Evolving Software. CMSC 433 Programming Language Technologies and Paradigms Spring Example. Some Motivations for This Refactoring CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Refactoring April 24, 2007 Lots of material taken from Fowler, Refactoring: Improving the Design of Existing Code 1 Evolving Software

More information

Refactoring. Chen Tang March 3, 2004

Refactoring. Chen Tang March 3, 2004 Refactoring Chen Tang March 3, 2004 What Is Refactoring (Definition) Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet

More information

Patterns in Software Engineering

Patterns in Software Engineering Patterns in Software Engineering Lecturer: Raman Ramsin Lecture 10 Refactoring Patterns Part 1 1 Refactoring: Definition Refactoring: A change made to the internal structure of software to make it easier

More information

AntiPatterns. EEC 421/521: Software Engineering. AntiPatterns: Structure. AntiPatterns: Motivation

AntiPatterns. EEC 421/521: Software Engineering. AntiPatterns: Structure. AntiPatterns: Motivation AntiPatterns EEC 421/521: Software Engineering Definition: An AntiPattern describes a commonly occurring solution to a problem that generates decidedly negative consequences Refactoring Reference: Refactoring

More information

void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) {

void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) { Refactoring References: Martin Fowler, Refactoring: Improving the Design of Existing Code; ; Bruce Wampler, The Essence of Object-Oriented Oriented Programming with Java and UML A recent OO technique that

More information

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11. University of Colorado, 2011

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11. University of Colorado, 2011 Refactoring Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture is taken

More information

Refactoring. Refactoring Techniques

Refactoring. Refactoring Techniques Refactoring Refactoring Techniques Code Quality is Important! Refactoring is... A disciplined technique for restructuring an existing body of code, altering its internal structure without changing its

More information

Refactoring. Herez Moise Kattan NUSP: João S. Brito Júnior NUSP:

Refactoring. Herez Moise Kattan NUSP: João S. Brito Júnior NUSP: Refactoring Herez Moise Kattan NUSP: 9860455 João S. Brito Júnior NUSP: 5889672 1 Definition Refactoring is the process of changing a software system in such a way that it does not* alter the external

More information

COURSE 11 DESIGN PATTERNS

COURSE 11 DESIGN PATTERNS COURSE 11 DESIGN PATTERNS PREVIOUS COURSE J2EE Design Patterns CURRENT COURSE Refactoring Way refactoring Some refactoring examples SOFTWARE EVOLUTION Problem: You need to modify existing code extend/adapt/correct/

More information

MSO Lecture Design by Contract"

MSO Lecture Design by Contract 1 MSO Lecture Design by Contract" Wouter Swierstra (adapted by HP, AL) October 8, 2018 2 MSO SO FAR Recap Abstract Classes UP & Requirements Analysis & UML OO & GRASP principles Design Patterns (Facade,

More information

Understading Refactorings

Understading Refactorings Understading Refactorings Ricardo Terra terra@dcc.ufmg.br Marco Túlio Valente mtov@dcc.ufmg.br UFMG, 2010 UFMG, 2010 Understanding Refactorings 1 / 36 Agenda 1 Overview 2 Refactoring 3 Final Considerations

More information

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

Objectives: On completion of this project the student should be able to: ENGI-0655/5232 Software Construction and Evolution Project 1 Reverse Engineering Refactoring & Object Oriented Design Due date November 10, 2009-4:00 pm 1. Aims The aim of this project is to give you more

More information

Designing with patterns - Refactoring. What is Refactoring?

Designing with patterns - Refactoring. What is Refactoring? Designing with patterns - Refactoring Bottom up based application of patterns Improving the design after it has been written What is Refactoring? Two definitions, the object and act of change in software

More information

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009 Refactoring, Part 2 Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09 University of Colorado, 2009 1 Introduction Credit where Credit is Due Some of the material for

More information

Software Design COSC 4353/6353 D R. R A J S I N G H

Software Design COSC 4353/6353 D R. R A J S I N G H Software Design COSC 4353/6353 D R. R A J S I N G H Week 5 Refactoring What is Refactoring? Code Smells Why Refactoring? Techniques IDEs What is Refactoring? Art of improving the design of existing code

More information

CSE 403 Lecture 21. Refactoring and Code Maintenance. Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke

CSE 403 Lecture 21. Refactoring and Code Maintenance. Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke CSE 403 Lecture 21 Refactoring and Code Maintenance Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke slides created by Marty Stepp http://www.cs.washington.edu/403/

More information

Refactoring. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Eivind Nordby

Refactoring. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Eivind Nordby Refactoring Faculty of Economic Sciences, Communication and IT 2011-09-21 Why Refactor Refactoring is one factor in keeping your system in shape Without continuous refactoring, the system will rot It takes

More information

Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered.

Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered. Testing Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered. System stability is the system going to crash or not?

More information

Introduction to Refactoring

Introduction to Refactoring Introduction to Refactoring Sutee Sudprasert 1 Credits Refactoring : Improving the design of existing code - Martin Fowler Design Patterns - GOF 2 What is refactoring? Refactoring is the process of changing

More information

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 Print Your Name: Page 1 of 8 Signature: Aludra Loginname: CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 (10:00am - 11:12am, Wednesday, October 5) Instructor: Bill Cheng Problems Problem #1 (24

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

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

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle Code Critique Identifying smells Refactoring Liskov Substitution Principle What goal are we designing to? What is the typical fix for code smells? What is a limitation of those fixes? How do we address

More information

Test Driven Development (TDD)

Test Driven Development (TDD) Test Driven Development (TDD) Test Driven Development Introduction Good programmers write code, great programmers write tests Never, in the field of programming, have so many owed so much to so few - Martin

More information

Patterns and Practices for Embedded TDD in C and C++ How we introduced TDD into our company

Patterns and Practices for Embedded TDD in C and C++ How we introduced TDD into our company Patterns and Practices for Embedded TDD in C and C++ How we introduced TDD into our company Work for Cornwall, England. based in Provide an embedded software development service. Introduced Lean/Agile

More information

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L 2 0 1 5 Introduction At this point, you are ready to beginning programming at a lower level How do you actually write your

More information

Software Testing Lecture 1. Justin Pearson

Software Testing Lecture 1. Justin Pearson Software Testing Lecture 1 Justin Pearson 2017 1 / 50 Four Questions Does my software work? 2 / 50 Four Questions Does my software work? Does my software meet its specification? 3 / 50 Four Questions Does

More information

Object Oriented Software Design - I

Object Oriented Software Design - I Object Oriented Software Design - I Unit Testing Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa November 28, 2011 G. Lipari (Scuola Superiore Sant Anna) Unit Testing November

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11. University of Colorado, 2011

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11. University of Colorado, 2011 Refactoring Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture is taken

More information

Refactoring Without Ropes

Refactoring Without Ropes Refactoring Without Ropes Roger Orr OR/2 Limited The term 'refactoring' has become popular in recent years; but how do we do it safely in actual practice? Refactoring... Improving the design of existing

More information

Hugbúnaðarverkefni 2 - Static Analysis

Hugbúnaðarverkefni 2 - Static Analysis Time to do some refactoring of my Java. Hugbúnaðarverkefni 2 - Static Analysis Fyrirlestrar 7 & 8 A Refactoring Micro-Example 15/01/2006 Dr Andy Brooks 1 Case Study Dæmisaga Reference A Refactoring Micro-Example,

More information

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011 Expanding Our Horizons CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011 1 Goals of the Lecture Cover the material in Chapter 8 of our textbook New perspective on objects and encapsulation

More information

Test Driven Development TDD

Test Driven Development TDD Test Driven Development TDD Testing Testing can never demonstrate the absence of errors in software, only their presence Edsger W. Dijkstra (but it is very good at the latter). Testing If it's worth building,

More information

Example of OO Design Refactoring

Example of OO Design Refactoring Example of OO Design Refactoring Robert B. France Colorado State University Fort Collins Colorado Robert B. France 1 What is design refactoring? Often an initial design is not a good design Design may

More information

Object-Oriented Programming Design and Analysis Elena Punskaya,

Object-Oriented Programming Design and Analysis Elena Punskaya, Object-Oriented Programming Design and Analysis Elena Punskaya, op205@cam.ac.uk!1 Object-Oriented Programming First programs: anything goes! 1960s-1970s: structured programming! - any computable function

More information

JUnit 3.8.1, 64. keep it simple stupid (KISS), 48

JUnit 3.8.1, 64. keep it simple stupid (KISS), 48 Index A accessor methods, 11, 152 add parameter technique, 189 190 add() method, 286 287, 291 algorithm, substituting, 104 105 AND logical operator, 172 architectural design patterns, 277 278 architecture,

More information

Software Engineering /48

Software Engineering /48 Software Engineering 1 /48 Topics 1. The Compilation Process and You 2. Polymorphism and Composition 3. Small Functions 4. Comments 2 /48 The Compilation Process and You 3 / 48 1. Intro - How do you turn

More information

Refactoring, 2nd Ed. A love story. Michael Hunger

Refactoring, 2nd Ed. A love story. Michael Hunger Refactoring, 2nd Ed. A love story Michael Hunger Michael Hunger Open Sourcerer Neo4j @mesirii It crashed at 940! I know what you're here for! Covers By: dev.to/rly Which Refactoring do you like most? Extract

More information

Refactoring. In essence we improve the design of the code after it has been written. That's an odd turn of phrase.

Refactoring. In essence we improve the design of the code after it has been written. That's an odd turn of phrase. Refactoring Process of changing software in such a way that it does not alter the external behavior of the code yet improves its internal structure. Disciplined way to clean up code that minimizes the

More information

CS 3 Introduction to Software Engineering. 3: Exceptions

CS 3 Introduction to Software Engineering. 3: Exceptions CS 3 Introduction to Software Engineering 3: Exceptions Questions? 2 Objectives Last Time: Procedural Abstraction This Time: Procedural Abstraction II Focus on Exceptions. Starting Next Time: Data Abstraction

More information

Refactoring Exercise

Refactoring Exercise Refactoring Exercise Maria Grazia Pia INFN Genova, Italy Maria.Grazia.Pia@cern.ch http://www.ge.infn.it/geant4/training/apc2017/ Exercise: The Video Store Grab basic concepts Get into the habit of refactoring

More information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

Refactoring. Paul Jackson. School of Informatics University of Edinburgh

Refactoring. Paul Jackson. School of Informatics University of Edinburgh Refactoring Paul Jackson School of Informatics University of Edinburgh Refactoring definition Refactoring (noun) is a change made to the internal structure of software to make it easier to understand,

More information

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1

More information

Reliable programming

Reliable programming Reliable programming How to write programs that work Think about reliability during design and implementation Test systematically When things break, fix them correctly Make sure everything stays fixed

More information

Composing Methods. Extract Method - Code that can be grouped - Meaningful name for method

Composing Methods. Extract Method - Code that can be grouped - Meaningful name for method Composing Methods Extract Method - Code that can be grouped - Meaningful name for method Inline Method - inverse of Extract Method - Method body is more obvious Extract Variable - Expression: hard to understand

More information

Construction: High quality code for programming in the large

Construction: High quality code for programming in the large Construction: High quality code for programming in the large Paul Jackson School of Informatics University of Edinburgh What is high quality code? High quality code does what it is supposed to do......

More information

Refactoring. George Dinwiddie idia Computing, LLC

Refactoring. George Dinwiddie idia Computing, LLC Refactoring George Dinwiddie idia Computing, LLC http://idiacomputing.com http://blog.gdinwiddie.com What is Refactoring? Refactoring is a disciplined technique for restructuring an existing body of code,

More information

Refactoring 101. By: Adam Culp

Refactoring 101. By: Adam Culp By: Adam Culp Twitter: @adamculp https://joind.in/14927 2 About me PHP 5.3 Certified Consultant at Zend Technologies Organizer SoFloPHP (South Florida) Organized SunshinePHP (Miami) Long distance (ultra)

More information

GitHub code samples. Appendix B

GitHub code samples. Appendix B Appendix B GitHub code samples The vast majority of the code samples in this book were taken from Microsoft Visual Studio 2013 solutions. Although not all of them are directly runnable, they can all be

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Completely

Completely Completely Test-Driven ian.truslove@nsidc.org @iantruslove UCAR Software Engineering Assembly, Feb 21, 2012 What s In It For Me? So, that TDD sounds great and all, but what about ? See some techniques

More information

Chapter 4. Computation. Bjarne Stroustrup.

Chapter 4. Computation. Bjarne Stroustrup. Chapter 4 Computation Bjarne Stroustrup www.stroustrup.com/programming Abstract Today, I ll present the basics of computation. In particular, we ll discuss expressions, how to iterate over a series of

More information

Test Driven Development (TDD), and Working with Legacy Code Using C# Workshop ( 4 days)

Test Driven Development (TDD), and Working with Legacy Code Using C# Workshop ( 4 days) Test Driven Development (TDD), and Working with Legacy Code Using C# Workshop ( 4 days) HOTEL DUBAI GRAND April 16 to 19-2018 Monday to Thursday ) (4 days) 9 am to 4 pm ISIDUS TECH TEAM FZE PO Box 9798

More information

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017 1 MSO Lecture 12 Wouter Swierstra (adapted by HP) October 26, 2017 2 LAST LECTURE Analysis matrix; Decorator pattern; Model-View-Controller; Observer pattern. 3 THIS LECTURE How to create objects 4 CATEGORIES

More information

Extreme programming XP 6

Extreme programming XP 6 Extreme programming XP 6 Planning Game 3 Planning Game Independent: Stories should be as independent as possible. When thinking of independence it is often easier to think of order independent. In other

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative

More information

Analysis of the Test Driven Development by Example

Analysis of the Test Driven Development by Example Computer Science and Applications 1 (2013) 5-13 Aleksandar Bulajic and Radoslav Stojic The Faculty of Information Technology, Metropolitan University, Belgrade, 11000, Serbia Received: June 18, 2013 /

More information

What? reorganising its internal structure

What? reorganising its internal structure What? Improving a computer program by reorganising its internal structure without t altering its external behaviour. (http://dictionary.reference.com/browse/refactoring ) Why? Improves the over all design

More information

Introduction to Programming

Introduction to Programming CHAPTER 1 Introduction to Programming Begin at the beginning, and go on till you come to the end: then stop. This method of telling a story is as good today as it was when the King of Hearts prescribed

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Lesson 13 Transcript: User-Defined Functions

Lesson 13 Transcript: User-Defined Functions Lesson 13 Transcript: User-Defined Functions Slide 1: Cover Welcome to Lesson 13 of DB2 ON CAMPUS LECTURE SERIES. Today, we are going to talk about User-defined Functions. My name is Raul Chong, and I'm

More information

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

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy Testing ENGI 5895: Software Design Andrew Vardy Faculty of Engineering & Applied Science Memorial University of Newfoundland March 6, 2017 Outline 1 Levels of Testing 2 Testing Methods 3 Test Driven Development

More information

VARIABLES AND TYPES CITS1001

VARIABLES AND TYPES CITS1001 VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data

More information

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 Contents 1 Exceptions and How They Work 1 1.1 Update to the Banking Example.............................

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

More information

Object Oriented Design and Programming Revision

Object Oriented Design and Programming Revision M.Sc Computer Science Object Oriented Design and Programming Revision Oded Lachish Email: oded@dcs.bbk.ac.uk Web Page: http://www.dcs.bbk.ac.uk/~oded/oodp12/oodp2012.html Question 1 (a) What is the motivation

More information

Lecture 15 Software Testing

Lecture 15 Software Testing Lecture 15 Software Testing Includes slides from the companion website for Sommerville, Software Engineering, 10/e. Pearson Higher Education, 2016. All rights reserved. Used with permission. Topics covered

More information

Refactoring Tested Code: Has Mocking. RefTest. Managing Refactoring in a Test. Driven World. Gone Wrong? Ben Stopford Royal Bank of Scotland

Refactoring Tested Code: Has Mocking. RefTest. Managing Refactoring in a Test. Driven World. Gone Wrong? Ben Stopford Royal Bank of Scotland RefTest Refactoring Tested Code: Has Mocking Driven World Gone Wrong? Managing Refactoring in a Test Ben Stopford Royal Bank of Scotland I've always been a old fashioned classic TDDer and thus far I don't

More information

Software Engineering

Software Engineering Software Engineering Lecture 13: Testing and Debugging Testing Peter Thiemann University of Freiburg, Germany SS 2014 Recap Recap Testing detect the presence of bugs by observing failures Recap Testing

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

Reengineering II. Transforming the System

Reengineering II. Transforming the System Reengineering II Transforming the System Recap: Reverse Engineering We have a detailed impression of the current state We identified the important parts We identified reengineering opportunities We have

More information

Detection of methods (or missing methods): Cleaning up some details of our implementation. Better Method Convention (1) --self

Detection of methods (or missing methods): Cleaning up some details of our implementation. Better Method Convention (1) --self Cleaning up some details of our implementation Dealing with missing methods The need for self -reference Dealing with tags Detection of methods (or missing methods): Use (no-method) to indicate that there

More information

Course December Adrian Iftene

Course December Adrian Iftene Course 10 12 December 2016 Adrian Iftene adiftene@info.uaic.ro Recapitulation QoS Functional Testing Non-Functional Testing Rotting Design Refactoring 2 QoS = ability to provide different priority to different

More information

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE Program 10: 40 points: Due Tuesday, May 12, 2015 : 11:59 p.m. ************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE *************

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

CSE 70 Final Exam Fall 2009

CSE 70 Final Exam Fall 2009 Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15

More information

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

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy Testing ENGI 5895: Software Design Andrew Vardy Faculty of Engineering & Applied Science Memorial University of Newfoundland March 6, 2017 Outline 1 Levels of Testing 2 Testing Methods 3 Test Driven Development

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 15 Testing Where we are Some very basic software engineering topics in the midst of tools Today: testing (how, why, some terms) Later:

More information

Refactoring. Section (JIA s) OTHER SOURCES

Refactoring. Section (JIA s) OTHER SOURCES Refactoring Section 7.2.1 (JIA s) OTHER SOURCES Code Evolution Programs evolve and code is NOT STATIC Code duplication Outdated knowledge (now you know more) Rethink earlier decisions and rework portions

More information

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << The sum of the integers 1 to 10 is  << sum << endl; Debugging Some have said that any monkey can write a program the hard part is debugging it. While this is somewhat oversimplifying the difficult process of writing a program, it is sometimes more time

More information

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT Object Oriented Programming Examiner s Report March 2017 A1. a) Explain what is meant by the following terms:

More information

Software Design and Analysis CSCI 2040

Software Design and Analysis CSCI 2040 Software Design and Analysis CSCI 2040 Introduce two important development practices in the context of the case studies: Test-Driven Development Refactoring 2 Logic is the art of going wrong with confidence

More information

3 Continuous Integration 3. Automated system finding bugs is better than people

3 Continuous Integration 3. Automated system finding bugs is better than people This presentation is based upon a 3 day course I took from Jared Richardson. The examples and most of the tools presented are Java-centric, but there are equivalent tools for other languages or you can

More information

Chapter 4 Computation

Chapter 4 Computation Chapter 4 Computation Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/spring_2011/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice using C++ Abstract

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

How We Refactor, and How We Know It

How We Refactor, and How We Know It Emerson Murphy-Hill, Chris Parnin, Andrew P. Black How We Refactor, and How We Know It Urs Fässler 30.03.2010 Urs Fässler () How We Refactor, and How We Know It 30.03.2010 1 / 14 Refactoring Definition

More information

COSC 2P91. Bringing it all together... Week 4b. Brock University. Brock University (Week 4b) Bringing it all together... 1 / 22

COSC 2P91. Bringing it all together... Week 4b. Brock University. Brock University (Week 4b) Bringing it all together... 1 / 22 COSC 2P91 Bringing it all together... Week 4b Brock University Brock University (Week 4b) Bringing it all together... 1 / 22 A note on practicality and program design... Writing a single, monolithic source

More information

Small changes to code to improve it

Small changes to code to improve it Small changes to code to improve it 1 Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior

More information

MSO Object Creation Singleton & Object Pool

MSO Object Creation Singleton & Object Pool MSO Object Creation Singleton & Object Pool Wouter Swierstra & Hans Philippi October 25, 2018 Object Creation: Singleton & Object Pool 1 / 37 This lecture How to create objects The Singleton Pattern The

More information

Refactorings. Refactoring. Refactoring Strategy. Demonstration: Refactoring and Reverse Engineering. Conclusion

Refactorings. Refactoring. Refactoring Strategy. Demonstration: Refactoring and Reverse Engineering. Conclusion Refactorings Refactoring What is it? Why is it necessary? Examples Tool support Refactoring Strategy Code Smells Examples of Cure Demonstration: Refactoring and Reverse Engineering Refactor to Understand

More information

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson More on Design CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson Outline Additional Design-Related Topics Design Patterns Singleton Strategy Model View Controller Design by

More information

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup. Chapter 5 Errors Hyunyoung Lee Based on slides by Bjarne Stroustrup www.stroustrup.com/programming 1 Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must

More information