Why Architecture Matters

Preview:

DESCRIPTION

Choosing the right software architecture for your project is very important. Besides the framework decision there are many other key issues you need to take into account and which have an impact on such things like maintainability, scalability and also the frequency of possible deployments. In this session you will to learn why you have to remove Co-dependency in your source code, which patterns there are for successful scaling and how the choosen framework influences your architecture.

Citation preview

Why Architecture mattersLars Jankowfsky, swoodoo.com

Freitag, 20. März 2009

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

Architecture

Freitag, 20. März 2009

Freitag, 20. März 2009

Zend Framework

symfony

cakePHPezComponents

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

long project lifetime

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

long project lifetime• code aging

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

long project lifetime• code aging

• big ball of mud

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

continuous maintenance

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

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

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

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

• deployment

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

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

• deployment

• scaling

Freitag, 20. März 2009

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

Success

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Success

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Success

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

Freitag, 20. März 2009

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

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Single responsibility principle

Freitag, 20. März 2009

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

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

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

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

K.I.S.S.

Freitag, 20. März 2009

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

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

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

Developing

Freitag, 20. März 2009

Art

Freitag, 20. März 2009

Evolution

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Evolving Architecture

Freitag, 20. März 2009

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

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

Principle of „bad smell“

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad smells?

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Bad smells?

• Do maintenance cost keep increasing?

Freitag, 20. März 2009

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

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

Freitag, 20. März 2009

dead code

Freitag, 20. März 2009

dead code

data classes

Freitag, 20. März 2009

comments „what not why“

dead code

data classes

Freitag, 20. März 2009

comments „what not why“

long methods

dead code

data classes

Freitag, 20. März 2009

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

Separation

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Layered Architecture

• separation of concerns

Freitag, 20. März 2009

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

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

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

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

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

SOA• Pro: makes scaling very easy

Freitag, 20. März 2009

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

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

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

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

Database

Freitag, 20. März 2009

Freitag, 20. März 2009

ZendDb

PDO

ADOdb

propel

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Database

• you need a database access layer

Freitag, 20. März 2009

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

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

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

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

Freitag, 20. März 2009

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

Object Layer Table Data Gateway Pattern

Freitag, 20. März 2009

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

Object Layer Table Data Gateway Pattern

Business LayerActive Record

Freitag, 20. März 2009

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

Object Layer Table Data Gateway Pattern

Business LayerActive Record

function giveMeMyData()

Freitag, 20. März 2009

MVC

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Controller• Common mistake: business logic in controller

Freitag, 20. März 2009

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

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

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

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

View

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

View• Use a template engine. Watch performance!

Freitag, 20. März 2009

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

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

TDD

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

TDD• enforces layered Architecture

Freitag, 20. März 2009

Freitag, 20. März 2009

Freitag, 20. März 2009

Freitag, 20. März 2009

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

Unit Tests

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Unit Tests• test a single class

• do not touch:

Freitag, 20. März 2009

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

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

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

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

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

Unit Tests

Integration Tests

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Integration Tests

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Integration Tests• test several classes

Freitag, 20. März 2009

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

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

Unit Tests

Integration Tests

Acceptance Tests

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Acceptance Tests

Freitag, 20. März 2009

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Why Architecture matters

Acceptance Tests• test functionality from „outside“

Freitag, 20. März 2009

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

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

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

Freitag, 20. März 2009

what if your tests run for hours ?

Freitag, 20. März 2009

framework !== software architecture

Freitag, 20. März 2009

evolve your architecture

Freitag, 20. März 2009

split your application into layers

Freitag, 20. März 2009

enforce proper usage of MVC

Freitag, 20. März 2009

wrap database access

Freitag, 20. März 2009

utilize test driven development

Freitag, 20. März 2009

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