Transcript
Page 1: Architecting for Change: An Agile Approach

Design and Architecture in Industry

The agile viewpoint

Ben Stopford

Thoughtworks

Page 2: Architecting for Change: An Agile Approach

What I’ll be covering

• The importance of expecting designs to change.

• The softer side of architecture needed to successfully guide a team.

• Methods for guiding design using patterns and frameworks.

• Problems that can occur with design.

Page 3: Architecting for Change: An Agile Approach

Why do we need to worry about Architecture and Design?

• Software evolves over time.

• Unmanaged change leads to spaghetti code bases where classes are highly coupled to one another.

• This makes them brittle and difficult to understand

Page 4: Architecting for Change: An Agile Approach

So how to we avoid this?

Page 5: Architecting for Change: An Agile Approach

We Architect our System

Page 6: Architecting for Change: An Agile Approach

… with UML

Page 7: Architecting for Change: An Agile Approach

AND…

We get to spot problems early on in the project lifecycle.

Why is that advantageous?

Page 8: Architecting for Change: An Agile Approach

Because it costs less

Low cost of change early in lifecycle

Page 9: Architecting for Change: An Agile Approach

So we have a plan for how to build our application before we

start coding.

All we need to do is follow the plan!!

Page 10: Architecting for Change: An Agile Approach

Well this is what we used to do…

…but problems kept cropping up…

Page 11: Architecting for Change: An Agile Approach

It was really hard to get the design right up front.

• The problems we face are hard.

• The human brain is bad at predicting all the implications of a complex solution up front.

• When we came to implementing solutions, our perspective would inevitably change and so would our design.

Page 12: Architecting for Change: An Agile Approach

And then…

…when we did get the design right…

…the users would go and change the requirements and we’d have

to redesign our model.

Page 13: Architecting for Change: An Agile Approach

Ahhh, those pesky users, why can’t they make up their minds?

Page 14: Architecting for Change: An Agile Approach

So…

…in summary…

Page 15: Architecting for Change: An Agile Approach

We find designing up front hard…

Page 16: Architecting for Change: An Agile Approach

...and a bit bureaucratic

Page 17: Architecting for Change: An Agile Approach

…and when we do get it right the users generally go and change

the requirements…

Page 18: Architecting for Change: An Agile Approach

…and it all changes in the next release anyway.

Page 19: Architecting for Change: An Agile Approach

So are we taking the right approach

Page 20: Architecting for Change: An Agile Approach

Software is supposed to be soft.

That means it is supposed to be easy to change.

Page 21: Architecting for Change: An Agile Approach

But is it?

• Small application are easy to change.

• Large applications generally are not.

Page 22: Architecting for Change: An Agile Approach

So is fixing the architecture and design up front the right

way to do it?

Page 23: Architecting for Change: An Agile Approach

Does the cost curve have to look like this?

Page 24: Architecting for Change: An Agile Approach

Can we design our systems so that we CAN change them later in

the lifecycle?

Page 25: Architecting for Change: An Agile Approach

The Cost of Change in an agile application

Page 26: Architecting for Change: An Agile Approach

How

Page 27: Architecting for Change: An Agile Approach

By architecting and designing for change

** But not designing for any specific changes

*** And writing lots and lots of tests

Page 28: Architecting for Change: An Agile Approach

Agile Development facilitates this

Code Base

Test

Test

Test

Page 29: Architecting for Change: An Agile Approach

Dynamic Design

• Similar to up-front design except that it is done little and often.

• Design just enough to solve the problem we are facing now, and NO MORE.

• Refactor it later when a more complex solution is needed.

Page 30: Architecting for Change: An Agile Approach

This means that your system’s design is constantly evolving.

Page 31: Architecting for Change: An Agile Approach

Making our key values:

• Changeability – because most software projects involve change.

• Comprehensibility – because the easier it is to understand, the easier it is to change.

Page 32: Architecting for Change: An Agile Approach

So what does this imply for the Architect?

Page 33: Architecting for Change: An Agile Approach

Architecture becomes about steering the application so that it remains easy to understand and

easy to change.

Page 34: Architecting for Change: An Agile Approach

With everyone being responsible for the design.

Page 35: Architecting for Change: An Agile Approach

So the architects role becomes about steering the applications

design through others.

Page 36: Architecting for Change: An Agile Approach

Shepherding the team!

Page 37: Architecting for Change: An Agile Approach

Shepherding the team

• People will always develop software in their own way. You can’t change this.

• You use the techniques you know to keep the team moving in the right direction.

• Occasionally one will run of in some tangential direction and when you see this you move them back.

Page 38: Architecting for Change: An Agile Approach

Timeline

Set-up Architecture

Push patterns and reuse

Watch for architectural breakers

Amend Architecture

Page 39: Architecting for Change: An Agile Approach

Aims:

–Encourage preferred patterns.

–Encourage reuse.

Tools:

–Communication

–Frameworks

Page 40: Architecting for Change: An Agile Approach

1. Architecture through reuse

• Good OO Design

• Common Libraries

• A Domain Model

Page 41: Architecting for Change: An Agile Approach

The importance of a Domain Model

• Simulate the business problem in software.

• Separate from any technically implied dependencies.

Page 42: Architecting for Change: An Agile Approach

2. Architecture through patterns

Page 43: Architecting for Change: An Agile Approach

Separation of Concerns:Layers and Services

Page 44: Architecting for Change: An Agile Approach

Example

GUI Data Access

•Scaling such a solution is problematic?

•Untangling the database code from the UI code makes each easier to understand. This might not matter for small applications but the effect is very noticeable as the application grows.

Page 45: Architecting for Change: An Agile Approach

Model-View-Controller

Page 46: Architecting for Change: An Agile Approach

A Real SOA and Layered System

Rightmove.com

Page 47: Architecting for Change: An Agile Approach

Business Services Communicating Asynchronously over a Bus

Persistence of Hips

Client Contacting Service - Services can only communicate over the bus. No Point to point communication (why).- Communication via neutral protocol

Page 48: Architecting for Change: An Agile Approach

SOA

• Architectural Pattern (Functional)

• Design Pattern (Technical)

Page 49: Architecting for Change: An Agile Approach

SOA as an Architectural Pattern

Provides separation between the implementations of different business services giving:– Scalability– Fungibility

Page 50: Architecting for Change: An Agile Approach

SOA as a Design Pattern

• Encourages separation of responsibilities into the different services.

• Forces communication between services to be at a business level => Promotes tight encapsulation.

• Asynchronous communication promotes statelessness of services.

Page 51: Architecting for Change: An Agile Approach

So how does SOA compare to a Component Based Model

• CBS using Corba is very similar:– Breakdown into component services– Language neutral protocol

• The key differences are:– Making services valid at a business level with the aim

being to integrate across the enterprise (mapping tools can be used to ensure the services match the business model).

– Communication only through business significant messages – this has interesting architectural implications.

Page 52: Architecting for Change: An Agile Approach

Layers and Tiers

Page 53: Architecting for Change: An Agile Approach

• Layers/Tiers provide a pattern that promotes separation between technical responsibilities.

• Services provide a pattern that promotes separation between functions at a business level.

Page 54: Architecting for Change: An Agile Approach

Layers vs. Services

• Services are generally wrapped behind well defined and controlled interfaces.

• Conversely the separation between layers is generally logical.

Page 55: Architecting for Change: An Agile Approach

Aside – Bob’s Website

Client

Application Layer

DB

Javascipt Calculation

Which way is best??

Client

Application Layer

DB

Server Calculation

Page 56: Architecting for Change: An Agile Approach

Layered ArchitectureHIP UI

HIP Service

Message Bus

Data Layer

Transformation Layer

Business Layer

Application Layer

Presentation Layer

The presentation layer is for pixel-painting.All logic should be delegated elsewhere.

The application layer is the glue between presentation and business.It is where MVC controllers live. Logic here is very light – simple field-level validation is as clever as it gets (e.g. “is it a date?”, “is it a number?”)

The business layer is a simulation of the business problem.It has no dependencies on the UI or on other technologies. Most importantly, it is isolated from persistence!(Similar to the Service Layer in RM+)

The transformation layer is the glue between business logic and non-UI technologies.It maps information between the business logic and some underlying tech.e.g. It maps HIPs into messages for the bus and into records for the database.

The data layer is represented by infrastructural tech. The RDBMS, and code to connect to the WebMethods bus sit here.

Web Pages

Controllers

Domain Model

Technology Abstraction& Mapping

Tech infrastructure

HIP DB

Page 57: Architecting for Change: An Agile Approach

What is the point of having layers?

Separation of Technical Concerns

Page 58: Architecting for Change: An Agile Approach

Example: Is a transformation layer a good idea?

Application Layer

Transformation Layer

Persistence Layer

Database

Domain Object

Table

ORM

Domain Object

Record Object

Table

Mapper

ORM

Page 59: Architecting for Change: An Agile Approach

UI Layer

Application Layer

Technical Decomposition into layering

Trade Service

Data Service

Pricing Service

Functional Decomposition into Services

Domain Model, Utilities etc

Reuse across services and potentially layers

Application separation and crosscutting

Page 60: Architecting for Change: An Agile Approach

Questions

• Is reuse across layers and services a good idea or does it break the encapsulation of those services or layers?

• What about if the services span multiple teams?

Page 61: Architecting for Change: An Agile Approach

3. Use of frameworks to enforce design principals

Page 62: Architecting for Change: An Agile Approach

For Example

• Inversion of Control and Spring, Picocontainer

• Functional separation with OO, CBS, SOA

• Layering with Hibernate, IBatis, Webwork

Page 63: Architecting for Change: An Agile Approach

Aside: What is wrong with the singleton pattern?

Page 64: Architecting for Change: An Agile Approach

It’s very hard to test applications when singletons are around

public void foo() { x = Fred.getInstance().getX();

…y = George.getInstance().getY();

…z = Arthur.getInstance().getZ();

}

Page 65: Architecting for Change: An Agile Approach

Dependency Injection

public void foo(X x, Y y, Z z)

{

}

Page 66: Architecting for Change: An Agile Approach

Spring

• Inversion of control/Dependency injection makes code easy to test.

• Helps you organise your middle tier.

• Get rid of (the static aspects of) singletons.

Page 67: Architecting for Change: An Agile Approach

Config.xml – Define Dependencies

<bean id="CurrencySpreadRecordDAO" class="com.dkib.gf.dao.CurrencySpreadRecordDAOImpl">

<property name="sqlMapClient" ref="sqlMapClient"/> </bean>

<bean id="MarketDataDao" class="com.dkib.gf.dao.MyMarketDataFacade">

<constructor-arg index="0" ref="DrivenPairRecordDAO"/> <constructor-arg index="1" ref="VolSmileRecordDAO"/> <constructor-arg index="2" ref="SpotRateRecordDAO"/> <constructor-arg index="3" ref="VolSpreadRecordDAO"/> <constructor-arg index="4" ref="CurrencySpreadRecordDAO"/> </bean>

Page 68: Architecting for Change: An Agile Approach

Spring performs constructionpublic class MyMarketDataFacade implements

MarketDataFacade {… public MyMarketDataFacade( DrivenPairRecordDAO drivenPairsDAO, VolSmileRecordDAO volSmileRecordDAO, SpotRateRecordDAO spotRateRecordDAO, VolSpreadRecordDAO volSpreadRecordDAO,

CurrencySpreadRecordDAO currencySpreadRecordDAO) {

Page 69: Architecting for Change: An Agile Approach

Look Up Service

public class DataLayer { private final ApplicationContext ctx;

public DataLayer() { ctx = new ClassPathXmlApplicationContext("config.xml"); } public MarketDataFacade getMarketDataFacade() { return (MarketDataFacade) ctx.getBean("MarketDataDao"); }}

Page 70: Architecting for Change: An Agile Approach

But…

These frameworks are not silver bullets. They each have their own problems.

Page 71: Architecting for Change: An Agile Approach

Avoiding Architectural Breakers

Course grained decisions that are hard to refactor away from. For example embedding business logic in a UI.

Page 72: Architecting for Change: An Agile Approach

Summary So Far

• Software is soft so design is an evolving process not a prescribed one.

• Architecture is about controlling the limits of design.

• Architecture is also about pushing a group of developers in a certain direction. It is a soft skill as much as a technical one.

• Patterns and frameworks are the tools the architect uses to do this.

Page 73: Architecting for Change: An Agile Approach

How design can go wrong

Page 74: Architecting for Change: An Agile Approach

The overuse of design patterns

=> Obtuse code

Page 75: Architecting for Change: An Agile Approach

Fragile Base Class Problem

• Why does this occur?

A

B C

Page 76: Architecting for Change: An Agile Approach

Solutions

• Favour composition over inheritance.

• Superclasses should call subclasses not the other way around

Page 77: Architecting for Change: An Agile Approach

Service Duplication Problem

UI Layer

Application Layer

Technical Decomposition into layering

Trade Service

Data Service

Pricing Service

Functional Decomposition into Services

Domain Model, Utilities etc

Page 78: Architecting for Change: An Agile Approach

Command/Executor Problem

Page 79: Architecting for Change: An Agile Approach

Solution

Be wary of functional decomposition and its tendency to

push you away from reuse

Page 80: Architecting for Change: An Agile Approach

In Conclusion

• Comprehensibility is the goal of design (followed by changeability).

• An architects role is primarily one of communicating and coordinating a common vision.

• If design is to be dynamic unit tests are mandatory.

Page 81: Architecting for Change: An Agile Approach

And finally…

Never listen to an architect who does not write code.

Conversely if you are an architect, make sure you get your hands

dirty.


Top Related