architecture refactoring - accelerating business success
TRANSCRIPT
Architecture Refactoring Accelerating Business Success
Ganesh Samarthyam, Corporate Trainer and Author www.designsmells.com
Architecture is all about realising business needs
Abstract business need (requirements)
Concrete implementation (code)
Architecture & Design
… but business needs keep changing!
…with that we need to adapt the software
City metaphor
“Cities grow, cities evolve, cities have parts that simply die while other
parts flourish; each city has to be renewed in order to meet the needs of its populace… Software-intensive systems
are like that. They grow, they evolve, sometimes they wither away, and
sometimes they flourish…”
Grady Booch in the foreword for “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014.
What is architecture debt?
…
Architecture)debt)
Architecture)smells)
Architecture)viola2ons)
Design)debt)
Design)smells)
Viola2ons)of)design)rules)
Test)debt)
Lack)of)tests)
Inadequate)test)coverage)
Code)debt)
Sta2c)analysis)tool)viola2ons)
Inconsistent)coding)style)
Key reasons for architecture refactoring
Address new business
needs
Increase feature velocity
Address architecture
decay
Realizing NFRs
Modernize
Reduce costs
Code refactoring
margin = c.getMargin();
if (c instanceof AbstractButton) {
margin = ((AbstractButton)c).getMargin();
} else if (c instanceof JToolBar) {
margin = ((JToolBar)c).getMargin();
} else if (c instanceof JTextComponent) {
margin = ((JTextComponent)c).getMargin();
}
Example: Refactoring for design smells
Earlier (relatively) mature work
Natural extension: Refactoring for architectural smells
The$red$lines$in$this$dependency$diagram$shows$
circular$dependencies$
Code refactoring Architecture refactoring
A module-level or class-level concern A system level concern that cuts across modules or sub-systems
Impact of refactoring is within a team Impact of refactoring is often across teams
Typically performed to improve the internal structure of the code
Performed for various reasons: cost, regulatory, security, performance, availability, …
Management buy-in typically not required Management buy-in is typically required
Upfront planning is typically (relatively) limited
Upfront planning and co-ordination (sometimes between teams) is often required
Unit tests are important to ensure that “behaviour is preserved”
Unit tests, integration tests, system tests, NFR tests, … are required
Risk of breaking the working software is relatively low
Risk of breaking the working software is relatively high
Real-world analogy: “fixing potholes”
Real-world analogy: “metro construction”
COTS(Commercial Off The Shelf)
FOSS(Free and Open Source Software)
Make Buy / Reuse
Proven technologies
Cutting-edge technologies
Architecting: the process of taking design decisions!
Cross-cutting concerns
Error/Exception handling
ConcurrencyPersistence
Event handling
Interaction and presentation
Source: SWEBOK v3
Case study: Using Structured EH
Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681409(v=vs.85).aspx
Structured Exception Handling in VC++
Standard Exception Handling supported in modern C++ compilers
bool SafeDiv(Number dividend, Number divisor, Number &result) {
try { result = dividend / divisor;
} catch(Number::divide_by_zero ex) { return false;
} return true;
}
BOOL SafeDiv(Number dividend, Number divisor, Number &result) {
__try { result = dividend / divisor;
} __catch(GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { return FALSE;
} return TRUE;
}
Handling persistence
Oracle DB
Component-1
Component-2
Component-N
[establish connection, SQL
queries, close connection…]
No clone within a component, but
duplication of code across components
How to support different databases?
[establish connection, SQL
queries, close connection…]
[establish connection, SQL
queries, close connection…]
Handling persistence
Component-1
Component-2
Component-N
Service layer / DAL
Case Study #1: Refactoring Windows
Refactoring Windows
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.
Refactoring Windows: Significant Characteristics
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.
Refactoring Windows
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.
Case Study #2: Refactoring Date & Time
support in JDK
Poor API design in JDK for date/time
e.g., in java.util.Date class, days start at 0,
months start at 1, years start at 1900!
Prior to Java 8, API design for date and time in JDK was poor
Date/Time related woes
// 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!
Example of a design smell in Date class
“Refused bequest” smell
Joda API & JSR 310
JSR 310: Java Date and Time API
Stephen Colebourne
LocalDate in java.time package
// using java.time.LocalDate LocalDate today = LocalDate.now();System.out.println(today);
$ java DateUse 2015-12-02
I can use (and hence depend upon) only date related functionality (not
time, zone, etc)
LocalDate in java.time package
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);
LocalDateTime todayAndNow = LocalDateTime.now(); System.out.println(todayAndNow);
ZonedDateTime todayAndNowInTokyo = ZonedDateTime.now(ZoneId.of("Asia/Tokyo")); System.out.println(todayAndNowInTokyo);
2015-12-02 17:37:22.647 2015-12-02T17:37:22.648 2015-12-02T21:07:22.649+09:00[Asia/Tokyo]
Many useful classes in java.time
Case Study #3: Refactoring JDK!
Tangles in JDK
Copyright © 2015, Oracle and/or its affiliates. All rights reserved
Copyright © 2015, Oracle and/or its affiliates. All rights reserved
Copyright © 2015, Oracle and/or its affiliates. All rights reserved
Project Jigsaw in Java 9
Modularize JDK & JRE
Hide platform internal details such as sun.misc
Provide a module system for Java developers
Case Study #4: Linux Kernel
Linux: Intended Architecture
Linux: Extracted Architecture
Key challenges in architecture refactoring
Getting management
buy-in
Fear of breaking working software
Lack of tool support
Merge process problems
Using tools for architecture refactoring
Key take-awaysArchitecture refactoring plays a key role in enabling business success
Architecture smells and violations contribute to technical debt (known as architecture debt)
Code refactoring and architecture refactoring are altogether different ballgames
We can learn from rich experience available on architecture refactoring
Refactoring for architecture smells is an effective way to learn software architecture!
“Architecture refactoring accelerates business success”
Image credits• http://sustainablecitiescollective.com/pratik-dave/244831/bangalore-exclusive-metro-india-having-profit-making-public-
transport-system
• http://www.medsoftwaresys.com/mss/wp-content/uploads/2012/04/reengineering.png
• http://topnews.in/files/Bangalore-Metro-Rail-Corporation-Ltd.jpg
• https://www.itdp.org/wp-content/uploads/2014/07/Chennai-Rendering.jpg
• http://www.vectors4all.net/preview/database-clip-art.jpg
• http://static.planetminecraft.com/files/resource_media/screenshot/1231/Windows-Vs-Mac_3072108.jpg
• http://manuel.midoriparadise.com/public_html/icons/linux-icon.png
• http://mortalpowers.com/posse/1280x1280/0DSC03205.JPG
• http://images.clipartpanda.com/server-computer-clipart-1216179635943364667jcartier_central_computer_1.svg.hi.png
• http://images.clipartpanda.com/cloud-icon-png-clouds.png
• http://www.clipartbest.com/cliparts/dc6/M5L/dc6M5LBc9.jpeg
• http://cdn.ttgtmedia.com/rms/computerweekly/refactor.jpg
• http://yellowairplane.com/Adventures/Falkland_Islands_War_Guestbook/Falkands_War_Malvinas_War_Photos/Jet_Fighter_Mirage_2000_Takeoff_Argentina.jpg
www.designsmells.com bit.ly/sgganesh @GSamarthyam