Post on 22-Aug-2015
Legacy Sins
Eberhard Wolff Freelancer
Eberhard Wolff - @ewolff
I’m a Software Architect. But I’m not doing architecture. !
Eberhard Wolff - @ewolff
How important is Software
Architecture?
Eberhard Wolff - @ewolff
Why would we care about Software
Architecture?
Eberhard Wolff - @ewolff
Software Architecture =Structure
Eberhard Wolff - @ewolff
Architecture Goals: Quality• All kinds of quality • Performance • Security • … • Focus of this presentation:
Changeability • Architects must understand
customers & priority
Eberhard Wolff - @ewolff
Architects must understand customer
Eberhard Wolff - @ewolff
Software ArchitectureSet of
structures comprise
software elements, relations among them, and
properties of both.
Eberhard Wolff - @ewolff
Why? • Can work on modules in isolation • Can work on collaboration of
modules
• Fits in my head • Dan North
Eberhard Wolff - @ewolff
Does He Care?
Eberhard Wolff - @ewolff
Why?Great
Architecture
Software Easy to change
High productivity
Low Cost
Eberhard Wolff - @ewolff
He Cares
€
Eberhard Wolff - @ewolff
Why?Great
Architecture
Software Easy to change
High productivity
Low Cost
Eberhard Wolff - @ewolff
What He Cares AboutGreat
Architecture
Software Easy to change
High productivity
Low Cost
Eberhard Wolff - @ewolff
Is architecture the only factor
for changeability?
Eberhard Wolff - @ewolff
What is the worst thing
we can have in a legacy code?
Eberhard Wolff - @ewolff
Great architecture
orautomated
tests?
Eberhard Wolff - @ewolff
No Automated Tests Worse• No way to find bugs • Changes almost impossible
• Legacy code = code without tests • Michael Feathers
Working Effectively with Legacy Code
Eberhard Wolff - @ewolff
Let’s add some
automated GUI tests
Eberhard Wolff - @ewolff
Automated GUI Tests• Easy to implement • Exactly what testers do manually • Easy to understand for customers • Test business processes • Safety net
Eberhard Wolff - @ewolff
Unit Tests
or automated GUI tests?
Eberhard Wolff - @ewolff
Many GUI Tests Worse • Fragile: Changes to GUI break test
• Business meaning of tests easily lost
• Takes long
• Often not reproducible
Eberhard Wolff - @ewolff
Automated GUI Tests
Automated Integration
Tests
Unit Tests
Manual Tests
Eberhard Wolff - @ewolff
Automated GUI Tests
Automated Integration
Tests
Unit Tests
Manual Tests
Eberhard Wolff - @ewolff
SlowUnreliableExpensive
Eberhard Wolff - @ewolff
Alternatives to automated GUI tests?
Eberhard Wolff - @ewolff
Textueller Akzeptanztest
Eberhard Wolff - @ewolff
Szenario• Möglicher Ablauf in einer Story
• Standardisierte Bestandteile: • Gegeben... (Kontext) • Wenn... (Ereignis) • Dann... (erwartetes Ergebnis)
Eberhard Wolff - @ewolff
Szenario: BeispielSzenario: Kunde registriert sich erfolgreich Gegeben ein neuer Kunde mit EMail eberhard.wolff@gmail.com Vorname Eberhard Name Wolff Wenn der Kunde sich registriert Dann sollte ein Kunde mit der EMail eberhard.wolff@gmail.com existieren Und es sollte kein Fehler gemeldet werden
Kontext
Ereignis
Erwartetes Ergebnis
Erwartetes Ergebnis
Eberhard Wolff - @ewolff
public class UserRegistrationSteps { private RegistrationService registrationService; private User kunde; private boolean fehler = false; // Initialisierung des RegistrationService ausgelassen @Given( "ein neuer Kunde mit EMail $email Vorname $vorname“ + "Name $name") public void gegebenKunde(String email, String vorname, String name) { kunde = new User(vorname, name, email); }
Eberhard Wolff - @ewolff
@When("der Kunde sich registriert") public void registerKunde() { try { registrationService.register(kunde); } catch (IllegalArgumentException ex) { fehler = true; } } @Then("sollte ein Kunde mit der EMail $email existieren") public void existiert(String email) { assertNotNull(registrationService.getByEMail(email)); } @Then("es sollte kein Fehler gemeldet werden") public void keinFehler() { assertFalse(fehler); } }
Eberhard Wolff - @ewolff
Test is about handling risk
Eberhard Wolff - @ewolff
Tests for Risks• Algorithm / calculation wrong:
Unit test • System failures: Unit tests • Wiring / collaboration:
Integration tests • Business process: Integration test • GUI: GUI test
Eberhard Wolff - @ewolff
Example: User Registration• Unit test Validations Database failure • Integration test Process • GUI test Everything displayed?
Eberhard Wolff - @ewolff
Not Tested• GUI won’t test validation • …or algorithms • …or the process
• Risks handled elsewhere
Eberhard Wolff - @ewolff
Automated GUI Tests
Automated Integration
Tests
Unit Tests
Manual Tests
Eberhard Wolff - @ewolff
Automated GUI Tests.
Automated Integration
Tests
Unit Tests
Manual Tests
Test Pyramid
Eberhard Wolff - @ewolff
Test Pyramid instead of Automated GUI tests
Eberhard Wolff - @ewolff
Great architecture
or fast & easy deployment?
Eberhard Wolff - @ewolff
Deployment• Manual deployment is error prone • Slow deployment Lots of code developed but not deployed i.e. more lean waste Slow feedback Slow time to recovery
Eberhard Wolff - @ewolff
Leseprobe: http://bit.ly/CD-Buch
Eberhard Wolff - @ewolff
Continuous Delivery: Build Pipeline
Commit Stage
Automated Acceptance
Testing
Automated Capacity Testing
Manual Explorative
Testing
Release
Eberhard Wolff - @ewolff
Continuous Delivery• Testing • + automated deployment
• Testing: reduce probability of errors • Automated deployment: better
mean time to repair
Eberhard Wolff - @ewolff
Continuous Delivery• Make software easier to change • & deploy
• Reliable and reproducible tests • Automated deployed • Fast & reliable
Eberhard Wolff - @ewolff
What is a great architecture?
Eberhard Wolff - @ewolff
GUI
Logic
Database
Eberhard Wolff - @ewolff
Is 3 Tier a great
architecture?
Eberhard Wolff - @ewolff
3 Tier• Actually layer: no distribution • By technology
• Layers can be replaced
• Layers can be developed independently
Eberhard Wolff - @ewolff
Do you replace e.g. the
persistence layer?
Eberhard Wolff - @ewolff
Is it really simple to add e.g. mobile
clients?
Eberhard Wolff - @ewolff
A better reason:
Fits in my head.
Eberhard Wolff - @ewolff
Redo the order
processing!
Eberhard Wolff - @ewolff
Add this to the
registration!
Eberhard Wolff - @ewolff
Can we change the
persistence technology
instead?
Eberhard Wolff - @ewolff
Please
Eberhard Wolff - @ewolff
What is a persistence
technology??
Eberhard Wolff - @ewolff
Registration Order Billing
GUI
Logic
Eberhard Wolff - @ewolff
Architecture• Should support changes • …with business value • Needs to model the domain • Hard to get right • Architect needs to understand the
domain
Eberhard Wolff - @ewolff
Is a great architecture free of cyclic
dependencies?
Eberhard Wolff - @ewolff
A B
A depends on B
Changes to B influence A
Eberhard Wolff - @ewolff
A B
A depends on B
Changes to B influence A B depends on A
Changes to A influence B
In fact one component Should be two components
Eberhard Wolff - @ewolff
Is a great architecture free of cyclic
dependencies?
Eberhard Wolff - @ewolff
Cyclic dependencies:
architects’ mortal sin
Eberhard Wolff - @ewolff
A B
A B
42
2
200
Eberhard Wolff - @ewolff
Other Architecture Metrics• High cohesion Elements of a module should belong together • Low coupling Modules should not depend on each other
Eberhard Wolff - @ewolff
Great Architecture• Don’t overrate cyclic dependencies!
• Consider other metrics
• Architecture by domain
Eberhard Wolff - @ewolff
The worst legacy
problems?
Eberhard Wolff - @ewolff
The project has a lot of cyclic dependencies!
I know. …but that doesn’t cause a lot of trouble
Eberhard Wolff - @ewolff
Architects must understand
customer & his quality demands
Eberhard Wolff - @ewolff
Quality• Changeability • Performance • Security • …
Eberhard Wolff - @ewolff
No two projects are
alike.
Eberhard Wolff - @ewolff
No general rules.
Eberhard Wolff - @ewolff
Sorry!
Eberhard Wolff - @ewolff
Software Easy to change
Automated tests
Test pyramid
Fast & easy deployment
Great Architecture
No cyclic dependencies
Low coupling
High cohesion
Eberhard Wolff - @ewolff
I’m a Software Architect. But I’m not doing architecture.
There is more to changeable software than architecture.
Eberhard Wolff - @ewolff
Thank You!