• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 22 pages
Class notes

Patterns 1 - Advanced Software Engineering

Document preview thumbnail
Preview 3 out of 22 pages

Lecture notes of 22 pages for the course Advanced Software Engineering at University of Wolverhampton (Test)

Content preview

Last Time – This time
! Program refactoring ! Design patterns basics
Advanced Software Engineering Topics




Design Patterns - 1




Dr John Kanyaru 1 2




Refactoring

Program Refactoring  Refactoring
 Program transformation that preserves semantics
 Improves software qualities
 Understandability, extensibility, reusability


Introduction  Why is refactoring important?
 Keep up with software evolution
 It may be necessary to improve design to support further
functionality


Dr JM Kanyaru 3 4

, Simple Refactoring So What?
for ( int radius=1, radius < 10; radius++ ) {
area = 3.1416 * radius * radius;  What was gained?
System.out.printf(“area radius %d= %f“,radius,area);
}  Understandability
 By looking at the code you can tell better what the
computation is doing
for ( int radius=1,radius< 10; radius++ )
area = computeArea(radius);  Anything lost?
System.out.printf(“area radius %d= %f“,radius,area);
}
 May be some performance
double computeArea(int radius) {  Short loop and compilers are smart (inlining)
return 3.1416 * radius * radius;
}

5 6




Another Simple Refactoring So What? (Again)
double computeArea(int radius) {
return 3.1416 * radius * radius;
 What was gained?
}  Understandability
 By looking at the code you can tell better what the
computation is doing
 Performance
static final double PI = 3.1416;  Maybe – possible compiler optimization, specially if
double computeArea(int radius) { variable is used in several places
return PI * radius * radius;
}  Anything lost?
 …

7 8

, Insights (1) Insights (2)
 Refactorings are relatively small changes
 A refactoring focus on one change at a time  To apply a refactoring certain conditions should hold
 Several refactorings can be applied to a program incrementally  Example: There should be a magic number in a
computation

program program’ program’’
 Each refactoring is an algorithm that consists of
several steps
refactoring refactoring
 Example:
 Declare a static final field with a meaningful name
 Initialize the field with the magic number
 Substitute the magic number in the original computation with
the new field


9 10




Insights – Recap Why Refactoring?

 Refactorings are relatively small changes  Improve design of software
 A refactoring focus on one change at a time
 Improve understandability
 Several refactorings can be applied to a program
incrementally
 Bug finding
 To apply a refactoring certain conditions should hold

 Each refactoring is an algorithm that consists of  Improve programming productivity
several steps  Code faster – because all of the above

11 12

Document information

Study
Unknown
Uploaded on
February 4, 2023
Number of pages
22
Written in
2022/2023
Type
Class notes
Professor(s)
Dr kevan buckley
Contains
All classes
$8.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Nawoda
5.0
(2)
Sold
2
Followers
2
Items
15
Last sold
3 year ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions