Download pdf - Why Architecture Matters

Transcript
Page 1: Why Architecture Matters

Why Architecture mattersLars Jankowfsky, swoodoo.com

Freitag, 20. März 2009

Page 2: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Lars Jankowfsky

• CTO swoodoo.com

• XP, agile development fanatic

• developing since 15+ years

• php since php/fi

• Software Architect > 10 years

Freitag, 20. März 2009

Page 3: Why Architecture Matters

Architecture

Freitag, 20. März 2009

Page 4: Why Architecture Matters

Freitag, 20. März 2009

Page 5: Why Architecture Matters

Zend Framework

symfony

cakePHPezComponents

Freitag, 20. März 2009

Page 6: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

long project lifetime

Freitag, 20. März 2009

Page 7: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

long project lifetime• code aging

Freitag, 20. März 2009

Page 8: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

long project lifetime• code aging

• big ball of mud

Freitag, 20. März 2009

Page 9: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

continuous maintenance

Freitag, 20. März 2009

Page 10: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

continuous maintenance• strong dependency -> „co-dependency“

Freitag, 20. März 2009

Page 11: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

continuous maintenance• strong dependency -> „co-dependency“

• deployment

Freitag, 20. März 2009

Page 12: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

continuous maintenance• strong dependency -> „co-dependency“

• deployment

• scaling

Freitag, 20. März 2009

Page 13: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Blaine Cook, Twitter's lead architect:

„For us, it’s really about scaling horizontally - to that end, Rails and Ruby haven’t been stumbling blocks, compared to any other language or framework. The performance boosts associated with a “faster” language would give us a 10-20% improvement, but thanks to architectural changes that Ruby and Rails happily accommodated, Twitter is 10000% faster than it was in January.“

Freitag, 20. März 2009

Page 14: Why Architecture Matters

Success

Freitag, 20. März 2009

Page 15: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Success

Freitag, 20. März 2009

Page 16: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Success

• D.R.Y. == Do Not Repeat Yourself

Freitag, 20. März 2009

Page 17: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Success

• D.R.Y. == Do Not Repeat Yourself

• Single responsibility principle

Freitag, 20. März 2009

Page 18: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Single responsibility principle

Freitag, 20. März 2009

Page 19: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Single responsibility principle

• "if it generates XML then it should not generate HTML"

Freitag, 20. März 2009

Page 20: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Single responsibility principle

• "if it generates XML then it should not generate HTML"

• "if you want to serialize to xml do not create "toxml" Method, instead pass $this to the XMLExporter"

Freitag, 20. März 2009

Page 21: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Success

• D.R.Y. == Do Not Repeat Yourself

• Single responsibility principle

• K.I.S.S.

Freitag, 20. März 2009

Page 22: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

K.I.S.S.

Freitag, 20. März 2009

Page 23: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

K.I.S.S.

• think in advance but don‘t think too complex

Freitag, 20. März 2009

Page 24: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

K.I.S.S.

• think in advance but don‘t think too complex

• before making any generalisation have at least two cases

Freitag, 20. März 2009

Page 25: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

K.I.S.S.

• think in advance but don‘t think too complex

• before making any generalisation have at least two cases

• the more abstractions the easier you can change it later

Freitag, 20. März 2009

Page 26: Why Architecture Matters

Developing

Freitag, 20. März 2009

Page 27: Why Architecture Matters

Art

Freitag, 20. März 2009

Page 28: Why Architecture Matters

Evolution

Freitag, 20. März 2009

Page 29: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Evolving Architecture

Freitag, 20. März 2009

Page 30: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Evolving Architecture

• Y.A.G.N.I. == You Ain‘t Gonna Need it

Freitag, 20. März 2009

Page 31: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Evolving Architecture

• Y.A.G.N.I. == You Ain‘t Gonna Need it

• Without refactoring there is no evolution

Freitag, 20. März 2009

Page 32: Why Architecture Matters

Principle of „bad smell“

Freitag, 20. März 2009

Page 33: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad smells?

Freitag, 20. März 2009

Page 34: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad smells?

• Do maintenance cost keep increasing?

Freitag, 20. März 2009

Page 35: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad smells?

• Do maintenance cost keep increasing?

• Simple features need too long to be implemented

Freitag, 20. März 2009

Page 36: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad smells?

• Do maintenance cost keep increasing?

• Simple features need too long to be implemented

• Small changes ripple through your system

Freitag, 20. März 2009

Page 37: Why Architecture Matters

Freitag, 20. März 2009

Page 38: Why Architecture Matters

dead code

Freitag, 20. März 2009

Page 39: Why Architecture Matters

dead code

data classes

Freitag, 20. März 2009

Page 40: Why Architecture Matters

comments „what not why“

dead code

data classes

Freitag, 20. März 2009

Page 41: Why Architecture Matters

comments „what not why“

long methods

dead code

data classes

Freitag, 20. März 2009

Page 42: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad Smells

• http://martinfowler.com/bliki/CodeSmell.html

• http://www.codinghorror.com/blog/archives/000589.html

Freitag, 20. März 2009

Page 43: Why Architecture Matters

Separation

Freitag, 20. März 2009

Page 44: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

Freitag, 20. März 2009

Page 45: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

• separation of concerns

Freitag, 20. März 2009

Page 46: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

• separation of concerns

• If they can live without each other - why to couple them?

Freitag, 20. März 2009

Page 47: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

• separation of concerns

• If they can live without each other - why to couple them?

• Find the boundaries and cut mercilessly.

Freitag, 20. März 2009

Page 48: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

• separation of concerns

• If they can live without each other - why to couple them?

• Find the boundaries and cut mercilessly.

• Do not bypass any layer!

Freitag, 20. März 2009

Page 49: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

• separation of concerns

• If they can live without each other - why to couple them?

• Find the boundaries and cut mercilessly.

• Do not bypass any layer!

• Separate modules/classes or go SOA

Freitag, 20. März 2009

Page 50: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA

Freitag, 20. März 2009

Page 51: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA• Pro: makes scaling very easy

Freitag, 20. März 2009

Page 52: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA• Pro: makes scaling very easy

• Pro: clear defined boundaries, no violations possible

Freitag, 20. März 2009

Page 53: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA• Pro: makes scaling very easy

• Pro: clear defined boundaries, no violations possible

• Pro: perfect for refactoring

Freitag, 20. März 2009

Page 54: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA• Pro: makes scaling very easy

• Pro: clear defined boundaries, no violations possible

• Pro: perfect for refactoring

• Pro: Deployment benefits

Freitag, 20. März 2009

Page 55: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA• Pro: makes scaling very easy

• Pro: clear defined boundaries, no violations possible

• Pro: perfect for refactoring

• Pro: Deployment benefits

• Con: integration testing gets more difficult

Freitag, 20. März 2009

Page 56: Why Architecture Matters

Database

Freitag, 20. März 2009

Page 57: Why Architecture Matters

Freitag, 20. März 2009

Page 58: Why Architecture Matters

ZendDb

PDO

ADOdb

propel

Freitag, 20. März 2009

Page 59: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

Freitag, 20. März 2009

Page 60: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

• you need a database access layer

Freitag, 20. März 2009

Page 61: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

• you need a database access layer

• go ORM if possible (performance!)

Freitag, 20. März 2009

Page 62: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

• you need a database access layer

• go ORM if possible (performance!)

• Active Record has business logic

Freitag, 20. März 2009

Page 63: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

• you need a database access layer

• go ORM if possible (performance!)

• Active Record has business logic

• business layer - not abstraction layer

Freitag, 20. März 2009

Page 64: Why Architecture Matters

Db Abstraction Layer PDO, ADOdb, ZendDb....

Freitag, 20. März 2009

Page 65: Why Architecture Matters

Db Abstraction Layer PDO, ADOdb, ZendDb....

Object Layer Table Data Gateway Pattern

Freitag, 20. März 2009

Page 66: Why Architecture Matters

Db Abstraction Layer PDO, ADOdb, ZendDb....

Object Layer Table Data Gateway Pattern

Business LayerActive Record

Freitag, 20. März 2009

Page 67: Why Architecture Matters

Db Abstraction Layer PDO, ADOdb, ZendDb....

Object Layer Table Data Gateway Pattern

Business LayerActive Record

function giveMeMyData()

Freitag, 20. März 2009

Page 68: Why Architecture Matters

MVC

Freitag, 20. März 2009

Page 69: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller

Freitag, 20. März 2009

Page 70: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller• Common mistake: business logic in controller

Freitag, 20. März 2009

Page 71: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller• Common mistake: business logic in controller

• Keep it out! Otherwise you will end with SQL in controller

Freitag, 20. März 2009

Page 72: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller• Common mistake: business logic in controller

• Keep it out! Otherwise you will end with SQL in controller

• I/O mapping to the model and view only

Freitag, 20. März 2009

Page 73: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller• Common mistake: business logic in controller

• Keep it out! Otherwise you will end with SQL in controller

• I/O mapping to the model and view only

• Kick Ass!

Freitag, 20. März 2009

Page 74: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

View

Freitag, 20. März 2009

Page 75: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

View• Use a template engine. Watch performance!

Freitag, 20. März 2009

Page 76: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

View• Use a template engine. Watch performance!

• No business logic in the template/html

Freitag, 20. März 2009

Page 77: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

View• Use a template engine. Watch performance!

• No business logic in the template/html

• Kick Ass!

Freitag, 20. März 2009

Page 78: Why Architecture Matters

TDD

Freitag, 20. März 2009

Page 79: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

TDD• enforces layered Architecture

Freitag, 20. März 2009

Page 80: Why Architecture Matters

Freitag, 20. März 2009

Page 81: Why Architecture Matters

Freitag, 20. März 2009

Page 82: Why Architecture Matters

Freitag, 20. März 2009

Page 83: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

TDD

• enforces layered Architecture

• use continuous integration (e.g. cruise control)

Freitag, 20. März 2009

Page 84: Why Architecture Matters

Unit Tests

Freitag, 20. März 2009

Page 85: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests

Freitag, 20. März 2009

Page 86: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

Freitag, 20. März 2009

Page 87: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

Freitag, 20. März 2009

Page 88: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

- database

Freitag, 20. März 2009

Page 89: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

- database

- network

Freitag, 20. März 2009

Page 90: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

- database

- network

- (files)

Freitag, 20. März 2009

Page 91: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

- database

- network

- (files)

• use mocks/stubs

Freitag, 20. März 2009

Page 92: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

- database

- network

- (files)

• use mocks/stubs

• provide fast feedback

Freitag, 20. März 2009

Page 93: Why Architecture Matters

Unit Tests

Integration Tests

Freitag, 20. März 2009

Page 94: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Integration Tests

Freitag, 20. März 2009

Page 95: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Integration Tests• test several classes

Freitag, 20. März 2009

Page 96: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Integration Tests• test several classes

• test communication between classes/modules

Freitag, 20. März 2009

Page 97: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Integration Tests• test several classes

• test communication between classes/modules

• they test full components

Freitag, 20. März 2009

Page 98: Why Architecture Matters

Unit Tests

Integration Tests

Acceptance Tests

Freitag, 20. März 2009

Page 99: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Acceptance Tests

Freitag, 20. März 2009

Page 100: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Acceptance Tests• test functionality from „outside“

Freitag, 20. März 2009

Page 101: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Acceptance Tests• test functionality from „outside“

• often build from „user stories“

Freitag, 20. März 2009

Page 102: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Acceptance Tests• test functionality from „outside“

• often build from „user stories“

• usually done with Selenium

Freitag, 20. März 2009

Page 103: Why Architecture Matters

what if fixture/mock preparation are much larger than tests?

Freitag, 20. März 2009

Page 104: Why Architecture Matters

what if your tests run for hours ?

Freitag, 20. März 2009

Page 105: Why Architecture Matters

framework !== software architecture

Freitag, 20. März 2009

Page 106: Why Architecture Matters

evolve your architecture

Freitag, 20. März 2009

Page 107: Why Architecture Matters

split your application into layers

Freitag, 20. März 2009

Page 108: Why Architecture Matters

enforce proper usage of MVC

Freitag, 20. März 2009

Page 109: Why Architecture Matters

wrap database access

Freitag, 20. März 2009

Page 110: Why Architecture Matters

utilize test driven development

Freitag, 20. März 2009

Page 111: Why Architecture Matters

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Thank you for your interest!

http://joind.in/talk/view/232

Freitag, 20. März 2009