refactoring for software architecture smells

55
Refactoring for Software Architecture Smells: Managing Architecture Debt Ganesh Samarthyam, Corporate Trainer and Author www.designsmells.com

Upload: ganesh-samarthyam

Post on 14-Jul-2015

779 views

Category:

Software


4 download

TRANSCRIPT

Page 1: Refactoring for Software Architecture Smells

Refactoring for Software Architecture Smells: Managing Architecture Debt

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

Page 2: Refactoring for Software Architecture Smells

Agenda• Introduction &

motivation

• What is architectural refactoring?

• Case studies in architectural refactoring

• Challenges in architecture refactoring

Page 3: Refactoring for Software Architecture Smells

Why care about this topic?

Page 4: Refactoring for Software Architecture Smells

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 5: Refactoring for Software Architecture Smells

“Infrastructure debt”!

Page 6: Refactoring for Software Architecture Smells

What is technical debt?When,&due&to&constraints,&I&design&quickly&and&dirty,&my&project&is&loaded&with&technical&debt&

Page 7: Refactoring for Software Architecture Smells

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 8: Refactoring for Software Architecture Smells

Refactoring a city?

Page 9: Refactoring for Software Architecture Smells

Is this refactoring?

Page 10: Refactoring for Software Architecture Smells

Architecture vs. agility?

Page 11: Refactoring for Software Architecture Smells

Key reasons for architecture refactoring

Business needs

Increase feature velocity

Address architecture

decay

Realizing NFRs

Modernize

Reduce costs

Page 12: Refactoring for Software Architecture Smells

Increase feature velocity

Page 13: Refactoring for Software Architecture Smells

Bubbles don’t crash!

Address NFRs

Page 14: Refactoring for Software Architecture Smells

Reduce costs

Page 15: Refactoring for Software Architecture Smells

Address architecture decay

Page 16: Refactoring for Software Architecture Smells

Modernize and get more profitable

Page 17: Refactoring for Software Architecture Smells

What if I don’t do architecture refactoring?

Page 18: Refactoring for Software Architecture Smells

Agenda• Introduction & motivation

• What is architectural refactoring?

• Case studies in architectural refactoring

• Challenges in architecture refactoring

Page 19: Refactoring for Software Architecture Smells

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 20: Refactoring for Software Architecture Smells

Example: Refactoring for design smells

Page 21: Refactoring for Software Architecture Smells

Earlier (relatively) mature work

Page 22: Refactoring for Software Architecture Smells

Natural extension: Refactoring for architectural smells

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

circular$dependencies$

Page 23: Refactoring for Software Architecture Smells

Example: Architectural refactoring

Remove one of the dependencies

Change dependency direction Move one of the dependencies

Page 24: Refactoring for Software Architecture Smells

Illustration: Refactoring for layering smells

Layer&A&

Layer&B&

Layer&C&

Layer&A&

Layer&B&

Layer&C&

Open layering Closed layering

Page 25: Refactoring for Software Architecture Smells

Refactoring “missing layer” smell

This  smell  arises  when  one  of  the  layers  is  missing  (or  when  no  layers  are  provided  at  all  when  

needed)  

Layer&A&

Layer&B&

DAL&

Layer&A&

Layer&B&

Page 26: Refactoring for Software Architecture Smells

Refactoring “violated layering” smell

Layer&A&

Layer&B&

Layer&C&

Layer&A&

Layer&B&

Layer&C&

Page 27: Refactoring for Software Architecture Smells

Architecture)smells)

Duplicate)design)ar3facts)

Unclear)role)of)en33es)

Inexpressive)or)complex)architecture)

Everything)centralized)

Over>generic)design)

Asymmetric)structure)or)behavior)

Dependency)cycles)

Unnecessary)dependencies)

Implicit)dependencies)

Page 28: Refactoring for Software Architecture Smells

Conway’ lawThe structure of a system mirrors the

structure of the organisation that

designed it

“Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.”Melvin E. Conway. "How do committees invent?", Datamation, 14(4):28–31, April 1968

Page 29: Refactoring for Software Architecture Smells

Structure of a compiler team

Front-end team

Back-end team

Front-end team

Back-end team

Platform I Platform 2

Page 30: Refactoring for Software Architecture Smells

Component interfaces vs. team boundaries

“Don't publish interfaces prematurely.

Modify your code ownership policies to smooth refactoring.”

– Martin Fowler (Refactoring, Addison-Wesley, 1999)

A guideline for code refactoring

A guideline for architecture refactoring

“Respect code ownership and retain team boundaries to

ensure smooth refactoring.”

Page 31: Refactoring for Software Architecture Smells

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, legal, 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 32: Refactoring for Software Architecture Smells

Agenda• Introduction & motivation

• What is architectural refactoring?

• Case studies in architectural refactoring

• Challenges in architecture refactoring

Page 33: Refactoring for Software Architecture Smells

Architecture represents the significant design decisions that shape a

system, where significant is measured by cost of change.

- Grady Booch (2006)

Page 34: Refactoring for Software Architecture Smells

NFRs

Constraints

TechnologyCross-cutting concerns

Others (e.g.: overall

structure)

Dimensions of ADs

Page 35: Refactoring for Software Architecture Smells

Case study: Skipping security layer

Page 36: Refactoring for Software Architecture Smells

Case study: Platform L & F

The example of “how much effort & time” it requires to provide the feature

to change the color of a button!

Page 37: Refactoring for Software Architecture Smells

Case study: OSS in a product

Page 38: Refactoring for Software Architecture Smells

COTS(Commercial Off The Shelf)

FOSS(Free and Open Source Software)

Make Buy / Reuse

Proven Modern / Latest

Page 39: Refactoring for Software Architecture Smells

Cross-cutting concerns

Error/Exception handling

ConcurrencyPersistence

Event handling

Interaction and presentation

Source: SWEBOK v3

Page 40: Refactoring for Software Architecture Smells

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 41: Refactoring for Software Architecture Smells

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 42: Refactoring for Software Architecture Smells

Handling persistence

Component-1

Component-2

Component-N

Service layer / DAL

Page 43: Refactoring for Software Architecture Smells

Agenda• Introduction & motivation

• What is architectural refactoring?

• Case studies in architectural refactoring

• Challenges in architecture refactoring

Page 44: Refactoring for Software Architecture Smells

Key challenges in architecture refactoring

Getting management

buy-in

Fear of breaking working software

Lack of tool support

Merge process problems

Page 45: Refactoring for Software Architecture Smells

How to get management buy-in?

logger.severe(“details”)

errlog.log(“details”)logger.error(“details”)

System.err.println(“details”)

Since ROI (Return On Investment) is not clear, how to get

management buy-in for this architectural refactoring?

Log4j java.util.logging custom log library SOPs

Page 46: Refactoring for Software Architecture Smells

Dealing with the fear of “breaking the working software”

Module 1 Module 2 Module N

How to validate architectural refactoring changes?

Currently through architecture, design, and code reviews + running system, integration, and unit tests =>

Can still break the working software!

Page 47: Refactoring for Software Architecture Smells

Lack of tool support

Unlike code refactoring, most architectural refactoring is manual

due to lack of tool support!

Page 48: Refactoring for Software Architecture Smells

Automated code smell detection and refactoring

Page 49: Refactoring for Software Architecture Smells

Lack of tool support

Lack of automated support for architectural refactoring

Inadequate support for detecting smells

Limited support for quantifying architectural debt

Page 50: Refactoring for Software Architecture Smells

Merge process problems

Challenge I: How to handle merges from distributed teams?

Challenge II: How to merge changes from long-running branches?

Page 51: Refactoring for Software Architecture Smells

Illustration: How to co-ordinate changes in distributed teams?

Module 1

Country 1

Module 2

Country 2

Module N

Country N

How do co-ordinate refactoring when code ownership is distributed with

teams across the globe? (more pronounced in refactoring situations)

Page 52: Refactoring for Software Architecture Smells

Illustration: How to deal with changes in long-running branches?

Module 1

Module 2

Module N

6 months

Page 53: Refactoring for Software Architecture Smells

Key take-awaysArchitecture smells and violations contribute to technical debt (known as architecture debt)

Architecture refactoring plays a key role in enhancing agility and enables business success

Code refactoring and architecture refactoring are altogether different ballgames

Architecture smells can be viewed in terms of Architectural Decisions (ADs)

Refactoring for replaying architecture debt is an emerging topic

Page 54: Refactoring for Software Architecture Smells

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

Page 55: Refactoring for Software Architecture Smells