refactoring aoms for agilept2010

60
Agile Refactoring for Making Systems More Adaptable Joseph W. Yoder The Refactory, Inc. June 25, 2010 [email protected] http://www.refactory.com

Upload: joseph-yoder

Post on 09-May-2015

1.102 views

Category:

Documents


0 download

TRANSCRIPT

Page 2: Refactoring AOMs For AgilePT2010

Slide - 2

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

The Refactory Principals

Refactory AffiliatesJoseph BerginFred Grossman

Bill Opdyke

John Brant

Brian Foote

Ralph Johnson

Don Roberts

Joe Yoder

Page 3: Refactoring AOMs For AgilePT2010

Slide - 3

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Agile to the Rescue???

Individuals and interactions over processes and tools

Working software over comprehensive documentation

Customer collaboration over contract negotiation

Responding to change over following a plan

That is, while there is value in the items on the right, we value the items on the left more.

…From the Agile Manifesto

Page 4: Refactoring AOMs For AgilePT2010

Slide - 4

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Agile Principles

Scrum, TDD, Refactoring, Regular Feedback, Testing, More Eyes, …

Good People! Face-To-Face conversation.

Continuous attention to technical excellence!

Motivated individuals with the environment and support they need. Retrospectives!

Allow Requirements to Change! Encourage Software Evolution as needed!

Page 5: Refactoring AOMs For AgilePT2010

Slide - 5

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Agile Encourages Changes

Very Little Upfront Design!

Piecemeal Growth! Small Iterations!

Late changes to the requirementsof the system!

Continuously Evolving the Architecture!

Adapting to Changes requires the code to change and Refactoring supports changes to the code in a “safe” way.

Page 6: Refactoring AOMs For AgilePT2010

Slide - 6

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Agile & Refactoring

A key part of Agile is to allow things to change and adapt as dictated by business needs!

To support these changes, Refactoring is encouraged by most Agile practitioners.

Agile has helped Refactoring be accepted into the mainstream development process (even sometimes encouraged).

Page 7: Refactoring AOMs For AgilePT2010

Slide - 7

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Ground Breaking Work

Before there was Agile…

Started at the University Of Illinois

Bill Opdyke & Don Roberts PHD Thesis

with Professor Ralph Johnson

Refactoring Browser by John Brant and Don Roberts (first commercial tool)

Page 8: Refactoring AOMs For AgilePT2010

Slide - 8

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Refactoring Definition

Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure…Martin Fowler, RefactoringImproving the Design of Existing Code; Addison Wesley , 1999

Page 9: Refactoring AOMs For AgilePT2010

Slide - 9

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

What is Refactoring

Refactoring is a controlled technique for improving the design of an existing code base

Small behavior-preserving transformations,

• Each of might be "too small to be worth doing“

• Cumulative effect of transformations is significant

• Small steps help reduce the risk of introducing errors

• Avoid having the system broken while you are carrying out the restructuring

• Gradually refactor a system over a period of time

Page 10: Refactoring AOMs For AgilePT2010

Slide - 10

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

A Simple Refactoring

Object

Concrete1 Concrete2

Object

Concrete1 Concrete2

NewAbstract

Create Empty Class

Page 11: Refactoring AOMs For AgilePT2010

Slide - 11

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

A Complex Refactoring

Array

Matrix

Matrix

MatrixRep

ArrayRep

rep

SparseRep IdentityRep

Adapted from Don Roberts, The Refactory, Inc.

Page 12: Refactoring AOMs For AgilePT2010

Slide - 12

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Refactoring Code Smells

A code smell is a hint that something has gone wrong somewhere in your code. Use the smell to track down the problem. KentBeck (with inspiration from the nose of Massimo Arnoldi) seems to have coined the phrase in the "OnceAndOnlyOnce" page, where he also said that code "wants to be simple". Bad Smells in Code was an essay by KentBeck and MartinFowler, published as Chapter 3 of Refactoring Improving The Design Of ExistingCode.

----Wards Wiki

Page 13: Refactoring AOMs For AgilePT2010

Slide - 13

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Code Smells Review

Duplicate Code, Long Method, Large Class,

Long Parameter List, Divergent Change,

Shotgun Surgery, Feature Envy, Data Clumps

Primitive Obsession, Switch Statements

Parallel Inheritance, Lazy Class

Speculative Generality, Temporary Field

Message Chains, Middle Man

Inappropriate Intimacy, Incomplete Lib Classes

Data Class, Refused Bequest, Comments

Page 14: Refactoring AOMs For AgilePT2010

Slide - 14

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Comments

We are not against comments but…

If you see large methods that have places where the code is commented, use Extract Method to pull that out to a comment

Page 15: Refactoring AOMs For AgilePT2010

Slide - 15

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Comments Example(Extract Method)

void printOwing (double amount) {

printBanner();

//print details

System.out.println (name: “ + _name);

System.out.println (amount: “ + amount);

…}

void printOwing (double amount) {

printBanner();

printDetails();

…}

void printDetails (double amount) {

System.out.println (name: “ + _name);

System.out.println (amount: “ + amount);}

Page 16: Refactoring AOMs For AgilePT2010

Slide - 16

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Extract Method Mechanics

Create a new method and name it after the intention of the code to extract.

Copy the extracted code from the source to the new method.

Scan the extracted code for references to any variables that are local to the source method.

See whether any temps are used only within extracted code.

Pass into target method as parameters local-scope variables that are read from the extracted code.

Replace the extracted code in the source method.

Page 17: Refactoring AOMs For AgilePT2010

Slide - 17

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Remove Method with Method ObjectClass Order …

double price() {

double primaryBasePrice;

double secondaryBasePrice;

double tertiaryBasePrice;

// long computation;

…}

Order

price()

PriceCalculator

primaryBasePrice

secondaryBasePrice

tertiaryBasePrice

compute()

1

return new PriceCalculator(this).compute()

Page 18: Refactoring AOMs For AgilePT2010

Slide - 18

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Remove Method toMethod Object Mechanics

Create a new class named after method.

Give the new class a final field for the object that hosted the original method.

Give the new class a constructor for the original object and each parameter.

Give the new class a compute method.

Copy the body of original method to compute.

Compile.

Replace the old method with the one that creates the new object and calls compute.

Page 19: Refactoring AOMs For AgilePT2010

Slide - 19

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Agile & Testing

Many Agile practices highly encourage Testing as one of their core practices.

Processes like XP support developers writing many unit tests (XUnit ).

Test Driven Development (TDD) is becoming highly accepted in Agile.

Testing was a key principle of Refactoring before there was Agile!

Page 20: Refactoring AOMs For AgilePT2010

Slide - 20

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Prerequisites of Refactoring

Since you are changing the code base, it is IMPORTANT to validate with tests.

There are also a time to refactor and a time to wait.

Need both Unit Testing and Integrated Tests for making sure nothing breaks

Page 21: Refactoring AOMs For AgilePT2010

Slide - 21

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Deciding Whether A Refactoring is Safe

"A refactoring shouldn't break a program.” What does this mean?

A safe refactoring is behavior preserving.

It is important not to violate: naming/ scoping rules. type rules.

"The program should perform the same after a refactoring as before.”

Satisfying timing constraints.

Page 22: Refactoring AOMs For AgilePT2010

Slide - 22

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Using Standard Tools

To be safe, must have tests

Should pass the tests beforeand after refactoring Commercial Testing Tools

Kent Beck’s Testing Framework(SUnit, JUnit, Nunit, …)

Take small steps, testing between each

Java and C# tools are getting better

Page 23: Refactoring AOMs For AgilePT2010

Slide - 23

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Catalogue of Refactorings

Composing Method

Moving Features

Organize Data

Simplifying Conditionals

Simpler Method Calls

Generalization

From Fowlers Book

Page 24: Refactoring AOMs For AgilePT2010

Slide - 24

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Refactoring andDesign Patterns (1)

What varies Design Pattern

Algorithms Strategy, Visitor

Actions Command

Implementations Bridge

Response to change Observer

Page 25: Refactoring AOMs For AgilePT2010

Slide - 25

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

What varies Design Pattern

Interactions between objects Mediator

Object being created Factory Method, Abstract

Factory, Prototype

Structure being created Builder

Traversal Algorithm Iterator

Object interfaces Adapter

Object behavior Decorator, State

Refactoring andDesign Patterns (2)

Page 26: Refactoring AOMs For AgilePT2010

Slide - 26

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Refactoring Summary

We have seen the mechanics for some of the Refactorings.

When you find smelly code, you often apply Refactorings to clean your code.

Refactorings do often apply Design Patterns.

Page 27: Refactoring AOMs For AgilePT2010

Slide - 27

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Building a System to Change

Sometimes it pays off to build a system that can respond quickly to change!

Page 28: Refactoring AOMs For AgilePT2010

Slide - 28

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Allowing Systems to AdaptRequirements change within

application’s domain.

Domain Experts know their domain best.

Business Rules are changing rapidly.

Applications have to quickly adapt tonew business requirements.

Agile Development Welcomes Changes to the Requirements, even late in the development!

One way to Adapt is to just Refactor to new business requirements…though sometimes…

Page 29: Refactoring AOMs For AgilePT2010

Slide - 29

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Forces – Shearing Layers

Who (Business Person, Analyst, Developer)

What (Business Rule, Persistence Layer,…)

When (How often, How fast)

There is a different rate of change on the system.

Foote & Yoder - Ball of Mud PLoPD4

Page 30: Refactoring AOMs For AgilePT2010

Slide - 30

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Newborn Screening Refactoring Example

Mother, Infant

Hospital, Lab

Doctor, HealthProf.

Blood Specimen

Page 31: Refactoring AOMs For AgilePT2010

Slide - 31

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Medical Observation –Basic OO Design Model

What happens when a new observation is required?

PhysicalMeasure

Blood

Observation Person

Measurement

convertTo:

Trait

traitValue Quantity

unit

amount

expressOnUnit:

expressOnUnits:

EyeColor

HairColor

Gender

Height

Weight

FeedingType

Hearing

Vision

*

Page 32: Refactoring AOMs For AgilePT2010

Slide - 32

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observation Design (1st Design)

Person

+address()

+phone()

+name()

Observation

+phenomenon()

-recordedDate : Date

-observedDate : Date

-duration : TimePeriod

Measurement

+observationValue()

Trait

+observationValue()

ObservationType

-phenomenon : Symbol

Quantity

+expressOnUnit(aUnit : Unit)

+expressOnUnits(unitCollection : Collection)

-unit : Unit

-amount : Number

* *1 1

1 1

Page 33: Refactoring AOMs For AgilePT2010

Slide - 33

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Name: John SmithMother: Sue Smith

Father:

Address:

Phone:

Height: 3 feet

Eyes Color: Blue

Observation DesignExample

Page 34: Refactoring AOMs For AgilePT2010

Slide - 34

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observation Design(instance diagram)

aPerson

name <John Smith>

obsCollection

aMeasurement

type

value

anObservationType

#height

aQuantity

value <3>

unit <ft>

aTrait

type

value <blue> anObservationType

#eyeColor

Page 35: Refactoring AOMs For AgilePT2010

Slide - 35

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Composing Observations

Observations can be more complex

Cholesterol

Components: HDL, LDL

Blood Pressure

Components: Systolic, Diastolic

Vision

Components: Left Eye, Right Eye

Page 36: Refactoring AOMs For AgilePT2010

Slide - 36

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Composite Observation Design (1st Refactoring)

Composite Pattern (GOF)

Make sure all tests still pass!

Person

+address()

+phone()

+name()

Observation

+phenomenon()

-recordedDate : Date

-observedDate : Date

-duration : TimePeriod

Measurement

+observationValue()

Trait

+observationValue()

ObservationType

-phenomenon : Symbol

Quantity

+expressOnUnit(aUnit : Unit)

+expressOnUnits(unitCollection : Collection)

-unit : Unit

-amount : Number

CompositeObservation

-observations : Collection

1..n

Page 37: Refactoring AOMs For AgilePT2010

Slide - 37

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observation DesignExample

Name: John SmithMother: Sue Smith

Father:

Address:

Phone:

Height: 3 feet

Eyes Color: Blue

Blood Pressure:

Systolic: 120 mmHg

Diastolic: 80 mmHg

Page 38: Refactoring AOMs For AgilePT2010

Slide - 38

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Composite Observation Design(instance diagram)

anObservType

<#BloodPressure>

aMeasurement

<120 mmHg>

aCompObs

anObserType

<#SYSTOLIC>

anotherMeasurement

<80 mmHg>

anObser-Type

<#DIASTOLIC>

Page 39: Refactoring AOMs For AgilePT2010

Slide - 39

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Composite and Primitive Observation DesignWhat we know about John?

aPerson

name <John Smith>

obsCollection

Height: 3 feet EyesColor: Blue

Diastolic: 80 mmHg

Systolic: 120 mmHg

BloodPressure: 120/80

Page 40: Refactoring AOMs For AgilePT2010

Slide - 40

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Validating Observations

Each Observation has its own setof legal values. Baby’s Weight: [0 30] pounds

HepatitisB: {positive, negative}

Left/Right Vision: {normal, abnormal}

GUI can enforce legal values but we want business rules in domain

objects

Page 41: Refactoring AOMs For AgilePT2010

Slide - 41

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

ObservationType

-phenomenon : Symbol

-validator : Validator

Validator

DiscreteValidator

-descriptorSet : Collection

NullValidator RangedValidator

-intervalSet : Collection

-validUnit : Unit

Validating Observations Design (2nd Refactoring)

Page 42: Refactoring AOMs For AgilePT2010

Slide - 42

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

ObservationType

type

Party

Measurement

value

value

value:

convertTo:

Trait

value

value

value:

Quantity

CompositeObservation

values

Observation

recordedDate

comments

Validator

DiscreteValidator

descriptorSet

RangedValidator

intervalSet

validUnit

NullValidator

Is everything an Observation?

How does the model specify the structure of the Composite?

What is the relationship between Trait and DiscreteValidator?

Overall Observation Design

First make sure original test cases pass and then add new test cases for the validators!

Page 43: Refactoring AOMs For AgilePT2010

Slide - 43

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

ObservationType

phenomenonType

isValid: obsValue

Party

Primitive Observation

observationValueCompositeObservation

Observation

recordedDate

comments

isValid

Validator

validatorName

isValid: obsValue

DiscreteValidator

descriptorSet

RangedValidator

intervalSet

validUnitPrimitiveObservation

Type

CompositeObservation

Type

NullValidator

Quantity

unit

quantity

convertTo:

DiscreteValues

Extend the Design by adding Composite to Type

-- Refactor the Metadata

Observation Design

Page 44: Refactoring AOMs For AgilePT2010

Slide - 44

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observation Design

ObservationType

phenomenonType

isValid: obsValue

Party

Primitive Observation

observationValueCompositeObservation

Observation

recordedDate

comments

isValid

Validator

validatorName

isValid: obsValue

DiscreteValidator

descriptorSet

RangedValidator

intervalSet

validUnitPrimitiveObservation

Type

CompositeObservation

Type

NullValidator

Quantity

unit

quantity

convertTo:

DiscreteValuesOperational level

Extend the Design by adding Composite to Type

-- Refactor the Metadata

Page 45: Refactoring AOMs For AgilePT2010

Slide - 45

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observation Design

ObservationType

phenomenonType

isValid: obsValue

Party

Primitive Observation

observationValueCompositeObservation

Observation

recordedDate

comments

isValid

Validator

validatorName

isValid: obsValue

DiscreteValidator

descriptorSet

RangedValidator

intervalSet

validUnitPrimitiveObservation

Type

CompositeObservation

Type

NullValidator

Quantity

unit

quantity

convertTo:

DiscreteValues

Knowledge level

Extend the Design by adding Composite to Type

-- Refactor the Metadata

Page 46: Refactoring AOMs For AgilePT2010

Slide - 46

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

anObserv-Type

<#COMP-GAL>

aMeasurement

<aQuantity>

aCompObs

anObser-Type

<#GAL>

anObser-Type

<#UDT>

anotherMeasurement

<anotherQuantity>

aRangedValidator

anotherRangedValidator

Observation Design(instance diagram)

Page 47: Refactoring AOMs For AgilePT2010

Slide - 47

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

anotherRangedValidator

anInfant

name

obsCollection

aMeasurement

type

value

anObservationType

#GestationalAge

aQuantity

value <36>

unit <weeks>

anObserv-Type

<#COMP-GAL>

aMeasurement

<aQuantity>

aCompObs

anObser-Type

<#GAL>

anotherMeasurement

<anotherQuantity>

anObser-Type

<#UDT>

aDiscreteValidator

aRangedValidator

Observation Design(instance diagram)

aRangedValidator

Page 48: Refactoring AOMs For AgilePT2010

Slide - 48

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observations: TypeObject

TypeObject

1..* elements

1 descriptor

elements 1..*

1..*

instance

ObservationType

phenomenonType

isValid: obsValue

Primitive Observation

observationValue

CompositeObservation

Observation

recordedDate

comments

isValid

PrimitiveObservation

Type

CompositeObservation

Type

Quantity

unit

quantity

convertTo:

DiscreteValues

Operational level

value 1..*

dvalue 1..*

Knowledge level

Page 49: Refactoring AOMs For AgilePT2010

Slide - 49

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observations: Properties

properties

1..*

elements 1..*

1..*

instance

Party

Primitive Observation

observationValueCompositeObservation

Observation

recordedDate

comments

isValid

Quantity

unit

quantity

convertTo:

DiscreteValuesOperational level

value 1..*

dvalue 1..*

Knowledge level

Page 50: Refactoring AOMs For AgilePT2010

Slide - 50

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observations: TypeSquarecontDescr 1

1 descriptor

1..* elements

1..* varType

elements 1..*

1..*

instance

ObservationType

phenomenonType

isValid: obsValue

Party

Primitive Observation

observationValue

CompositeObservation

Observation

recordedDate

comments

isValid

PrimitiveObservation

Type

CompositeObservation

Type

Quantity

unit

quantity

convertTo:

DiscreteValuesOperational level

PartyType

1 descriptor

properties

1..*

1..*

value 1..*

dvalue 1..*

Knowledge level

Page 51: Refactoring AOMs For AgilePT2010

Slide - 51

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Observations: Strategy

guard 1ObservationType

phenomenonType

isValid: obsValue

Validator

validatorName

isValid: obsValue

DiscreteValidator

descriptorSet

RangedValidator

intervalSet

validUnit

PrimitiveObservation

Type

CompositeObservation

TypeNullValidator

Operational level

1..* elements

1..* type

Knowledge level

Page 52: Refactoring AOMs For AgilePT2010

Slide - 52

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Medical Observations Design

1 descriptor

elements 1..*

1..*

instance

ObservationType

phenomenonType

isValid: obsValue

Party

Primitive Observation

observationValue

CompositeObservation

Observation

recordedDate

comments

isValid

Validator

validatorName

isValid: obsValue

DiscreteValidator

descriptorSet

RangedValidator

intervalSet

validUnitPrimitiveObservation

Type

CompositeObservation

Type

NullValidator

Quantity

unit

quantity

convertTo:

DiscreteValuesOperational level

1..* elements

guard 11..* type

PartyType

1 descriptor

properties

1..*

1..*

value 1..*

dvalue 1..*

Knowledge level

1..* varType

contDescr 1Entities

Attributes

Behavior

Page 53: Refactoring AOMs For AgilePT2010

Slide - 53

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Strategies/Interpreters/RuleObjects(Behavior/Methods)

Design Patterns - GOF95

Composite Strategies Interpreter

SomeStrategy

+sharedInterface()

-sharedAttributes : someType

Strategy1 Strategy2 StragegyN

...

Entity

+someOperations()

-specificAttribues : type

Strategy2.1 Strategy2.2

*

*

1

1

RuleObject

PrimitiveRule CompositeRule

ANDCondition ORCondition NOTCondition

*

1

Page 54: Refactoring AOMs For AgilePT2010

Slide - 54

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Composite Strategies

Problem: Strategy leads to a big class hierarchy, one class for each kind of policy.

Solution: Make Composite Strategies using Primitive Operations.

=> Interpreter pattern

Page 55: Refactoring AOMs For AgilePT2010

Slide - 55

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Entity

+valueUsing:()

Attribute

EntityType

+name

+type

AttributeType

-type

1 1

-attributes *

1

1

-type

*

-children *

1

-attributeTypes1

*

+valueUsing:()

Rule

TableLookup BinaryOperation

+value

Constant

1

-rules

*

1 *

*

*

1

*

CompositeRule

Accountability AccountabilityType-type

1 1

1

-children*-children *

1

-accountabilities1

* -children *

1

-accountabilitieTypes1

*

Adaptive Object Model “Common Architecture”

Classes with Attributes andRelationships

Behavior

Operational Knowledge (meta)

Page 56: Refactoring AOMs For AgilePT2010

Slide - 56

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Process for Developing Adaptable Systems

Developed Iteratively and Incrementally.

Be Agile, Scrum, XP, Retrospective

Get Customer Feedback early and often.

User Scenarios – User Stories…

Add flexibility only when and where needed.

Provide Test Cases and Suites for both theObject-Model and the Meta-Model.

Develop Support Tools and Editors for manipulating the metadata.

Very similar to Evolving Frameworksby Roberts and Johnson PLoPD3

Page 57: Refactoring AOMs For AgilePT2010

Slide - 57

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Refactoring Addresses SomeKey Leverage Points

Refactoring is a technique that works with Brooks’ “promising attacks” (from “No Silver Bullet”):

buy rather than build: restructuring interfaces to support commercial SW

grow don’t build software: software growth involves restructuring (isn’t this core to Agile???)

requirements refinements and rapid prototyping: refactoring supports such design exploration, and adapting to changing customer needs

support great designers: a tool in a designer’s tool chest.

Page 58: Refactoring AOMs For AgilePT2010

Slide - 58

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

Papers and Web Sites

Bill Opdyke’s Thesis

Don Robert’s Thesis http://st-www.cs.illinois.edu/users/droberts/thesis.pdf

Refactoring Browser http://st-www.cs.illinois.edu/users/brant/Refactory

Evolving Frameworks http://st-www.cs.uiuc.edu/users/droberts/evolve.html

Extreme Programming http://www.c2.com/cgi-bin/wiki?ExtremeProgramming

Page 59: Refactoring AOMs For AgilePT2010

Slide - 59

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

More Web Sites

Wiki wiki web http://c2.com/cgi/wiki?WikiPagesAboutRefactoring

The Refactory, Inc. http://www.refactory.com

Martin Fowler’s Refactoring Pages http://www.refactoring.com/

Adaptive Object Models http://www.adaptiveobjectmodel.com/

Page 60: Refactoring AOMs For AgilePT2010

Slide - 60

Agile Refactoring for Making Systems More Adaptable Copyright 2010, Joseph W. Yoder & The Refactory, Inc.

That’s All