Awareness of design smells - indicators of common design problems - helps developers or software engineers understand mistakes made while designing and apply design principles for creating high-quality designs. This tech talk provides insights gained from performing refactoring in real-world projects to improve refactoring and reduce the time and costs of managing software projects. The tech talk also presents insightful anecdotes and case studies drawn from the trenches of real-world projects. By attending this tech talk, you will know pragmatic techniques for refactoring design smells to manage technical debt and to create and maintain high-quality software in practice.
Contents overview:
* Why care about design principles, design quality, or design smells?
* Refactoring as the primary means for repaying technical debt
* Smells that violate abstraction, encapsulation, modularisation, or hierarchy
* Tools and techniques for refactoring
10. "... a delightful, engaging, actionable read... you have
in your hand a veritable field guide of smells... one
of the more interesting and complex expositions of
software smells you will ever find..."
- From the foreword by Grady Booch (IBM Fellow and Chief Scientist for
Software Engineering, IBM Research)
11. "This is a good book about ‘Design Smells’ – actually
a great book – nicely organized - clearly written with
plenty of examples and a fair sprinkling of
anecdotes."
- Will Tracz (Principal Research Scientist & Fellow, Lockheed Martin)
(review in ACM SIGSOFT Software Engineering Notes)
12. Fundamental Principles in Software Design
Principles*
Abstrac/on*
Encapsula/on*
Modulariza/on*
Hierarchy*
15. Is this a Smell?
abstract class Printer {
private Integer portNumber = getPortNumber();
abstract Integer getPortNumber();
public static void main(String[]s) {
Printer p = new LPDPrinter();
System.out.println(p.portNumber);
}
}
class LPDPrinter extends Printer {
/* Line Printer Deamon port no is 515 */
private Integer defaultPortNumber = 515;
Integer getPortNumber() {
return defaultPortNumber;
}
}
prints
“null”!
22. Discussion Example
// using java.util.Date
Date today = new Date();
System.out.println(today);
$ java DateUse
Wed Dec 02 17:17:08 IST 2015
Why should we get the
time and timezone details
if I only want a date? Can
I get rid of these parts?
No!
23. So What!
Date today = new Date();
System.out.println(today);
Date todayAgain = new Date();
System.out.println(todayAgain);
System.out.println(today.compareTo(todayAgain) == 0);
Thu Mar 17 13:21:55 IST 2016
Thu Mar 17 13:21:55 IST 2016
false
What is going
on here?
27. Refactored Example …
You can use only date,
time, or even timezone,
and combine them as
needed!
LocalDate today = LocalDate.now();
System.out.println(today);
LocalTime now = LocalTime.now();
System.out.println(now);
ZoneId id = ZoneId.of("Asia/Tokyo");
System.out.println(id);
LocalDateTime todayAndNow = LocalDateTime.now();
System.out.println(todayAndNow);
ZonedDateTime todayAndNowInTokyo = ZonedDateTime.now(ZoneId.of("Asia/Tokyo"));
System.out.println(todayAndNowInTokyo);
2016-03-17
13:28:06.927
Asia/Tokyo
2016-03-17T13:28:06.928
2016-03-17T16:58:06.929+09:00[Asia/Tokyo]
35. Language Features & Refactoring
public static void main(String []file) throws Exception {
// process each file passed as argument
// try opening the file with FileReader
try (FileReader inputFile = new FileReader(file[0])) {
int ch = 0;
while( (ch = inputFile.read()) != -1) {
// ch is of type int - convert it back to char
System.out.print( (char)ch );
}
}
// try-with-resources will automatically release FileReader object
}
public static void main(String []file) throws Exception {
Files.lines(Paths.get(file[0])).forEach(System.out::println);
}
Java 8 lambdas and streams
37. Refactoring Windows!
“A large number of dependencies at the module level
could be reduced and optimized to:
* make modular reasoning of the system more efficient
* maximize parallel development efficiency
* avoid unwanted parallel change interference
* selectively rebuild and retest subsystems effectively”
Refactoring performed to reduce
and optimize dependencies - by
creating and enforcing layering
Source: Kim, Miryung, Thomas Zimmermann, and Nachiappan Nagappan. "An Empirical Study of RefactoringChallenges and Benefits at Microsoft."
IEEE Transactions on Software Engineering 7 (2014): 1-1.
38. Refactoring Windows!
Refactoring decisions made after substantial
analysis of existing dependency structure
Refactoring effort was centralized and top
down with designated team for refactoring
Use of custom refactoring tools (MaX)
and processes (quality gate check)
Source: Kim, Miryung, Thomas Zimmermann, and Nachiappan Nagappan. "An Empirical Study of RefactoringChallenges and Benefits at Microsoft."
IEEE Transactions on Software Engineering 7 (2014): 1-1.
53. Upcoming Java 8 Bootcamp
Modern Programming with Java 8
Refactor your legacy applications using Java 8 features
Register here: https://www.townscript.com/e/java8-refactoring