architecture refactoring - accelerating business success

48
Architecture Refactoring Accelerating Business Success Ganesh Samarthyam, Corporate Trainer and Author www.designsmells.com

Upload: ganesh-samarthyam

Post on 16-Apr-2017

213 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Architecture refactoring - accelerating business success

Architecture Refactoring Accelerating Business Success

Ganesh Samarthyam, Corporate Trainer and Author www.designsmells.com

Page 2: Architecture refactoring - accelerating business success

Architecture is all about realising business needs

Abstract business need (requirements)

Concrete implementation (code)

Architecture & Design

Page 3: Architecture refactoring - accelerating business success

… but business needs keep changing!

Page 4: Architecture refactoring - accelerating business success

…with that we need to adapt the software

Page 5: Architecture refactoring - accelerating business success

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.

Page 6: Architecture refactoring - accelerating business success

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)

Page 7: Architecture refactoring - accelerating business success

Key reasons for architecture refactoring

Address new business

needs

Increase feature velocity

Address architecture

decay

Realizing NFRs

Modernize

Reduce costs

Page 8: Architecture refactoring - accelerating business success

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();

}

Page 9: Architecture refactoring - accelerating business success

Example: Refactoring for design smells

Page 10: Architecture refactoring - accelerating business success

Earlier (relatively) mature work

Page 11: Architecture refactoring - accelerating business success

Natural extension: Refactoring for architectural smells

The$red$lines$in$this$dependency$diagram$shows$

circular$dependencies$

Page 12: Architecture refactoring - accelerating business success

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”

Page 13: Architecture refactoring - accelerating business success

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!

Page 14: Architecture refactoring - accelerating business success

Cross-cutting concerns

Error/Exception handling

ConcurrencyPersistence

Event handling

Interaction and presentation

Source: SWEBOK v3

Page 15: Architecture refactoring - accelerating business success

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;

}

Page 16: Architecture refactoring - accelerating business success

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…]

Page 17: Architecture refactoring - accelerating business success

Handling persistence

Component-1

Component-2

Component-N

Service layer / DAL

Page 18: Architecture refactoring - accelerating business success

Case Study #1: Refactoring Windows

Page 19: Architecture refactoring - accelerating business success

Refactoring Windows

Page 20: Architecture refactoring - accelerating business success

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.

Page 21: Architecture refactoring - accelerating business success

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.

Page 22: Architecture refactoring - accelerating business success

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.

Page 23: Architecture refactoring - accelerating business success

Case Study #2: Refactoring Date & Time

support in JDK

Page 24: Architecture refactoring - accelerating business success

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

Page 25: Architecture refactoring - accelerating business success

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!

Page 26: Architecture refactoring - accelerating business success

Example of a design smell in Date class

“Refused bequest” smell

Page 27: Architecture refactoring - accelerating business success

Joda API & JSR 310

JSR 310: Java Date and Time API

Stephen Colebourne

Page 28: Architecture refactoring - accelerating business success

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)

Page 29: Architecture refactoring - accelerating business success

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]

Page 30: Architecture refactoring - accelerating business success

Many useful classes in java.time

Page 31: Architecture refactoring - accelerating business success

Case Study #3: Refactoring JDK!

Page 32: Architecture refactoring - accelerating business success

Tangles in JDK

Page 33: Architecture refactoring - accelerating business success

Copyright © 2015, Oracle and/or its affiliates. All rights reserved

Page 34: Architecture refactoring - accelerating business success

Copyright © 2015, Oracle and/or its affiliates. All rights reserved

Page 35: Architecture refactoring - accelerating business success

Copyright © 2015, Oracle and/or its affiliates. All rights reserved

Page 36: Architecture refactoring - accelerating business success

Project Jigsaw in Java 9

Modularize JDK & JRE

Hide platform internal details such as sun.misc

Provide a module system for Java developers

Page 37: Architecture refactoring - accelerating business success

Case Study #4: Linux Kernel

Page 38: Architecture refactoring - accelerating business success

Linux: Intended Architecture

Page 39: Architecture refactoring - accelerating business success

Linux: Extracted Architecture

Page 40: Architecture refactoring - accelerating business success

Key challenges in architecture refactoring

Getting management

buy-in

Fear of breaking working software

Lack of tool support

Merge process problems

Page 41: Architecture refactoring - accelerating business success

Using tools for architecture refactoring

Page 42: Architecture refactoring - accelerating business success
Page 43: Architecture refactoring - accelerating business success
Page 44: Architecture refactoring - accelerating business success
Page 45: Architecture refactoring - accelerating business success

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!

Page 46: Architecture refactoring - accelerating business success

“Architecture refactoring accelerates business success”

Page 47: Architecture refactoring - accelerating 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