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.
2. Why Architecture matters PHPCon Italia 2009
Lars Jankowfsky
• CTO swoodoo.com
• XP, agile development fanatic
• developing since 15+ years
• php since php/fi
• Software Architect > 10 years
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
5. Zend Framework
symfony
cakePHP
ezComponents
Freitag, 20. März 2009
6. Why Architecture matters PHPCon Italia 2009
long project lifetime
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
7. Why Architecture matters PHPCon Italia 2009
long project lifetime
• code aging
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
8. Why Architecture matters PHPCon Italia 2009
long project lifetime
• code aging
• big ball of mud
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
9. Why Architecture matters PHPCon Italia 2009
continuous maintenance
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
10. Why Architecture matters PHPCon Italia 2009
continuous maintenance
• strong dependency -> „co-dependency“
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
11. Why Architecture matters PHPCon Italia 2009
continuous maintenance
• strong dependency -> „co-dependency“
• deployment
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
12. Why Architecture matters PHPCon Italia 2009
continuous maintenance
• strong dependency -> „co-dependency“
• deployment
• scaling
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
13. Why Architecture matters PHPCon Italia 2009
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.“
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
15. Why Architecture matters PHPCon Italia 2009
Success
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
16. Why Architecture matters PHPCon Italia 2009
Success
• D.R.Y. == Do Not Repeat Yourself
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
17. Why Architecture matters PHPCon Italia 2009
Success
• D.R.Y. == Do Not Repeat Yourself
• Single responsibility principle
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
18. Why Architecture matters PHPCon Italia 2009
Single responsibility principle
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
19. Why Architecture matters PHPCon Italia 2009
Single responsibility principle
• quot;if it generates XML then it should not generate HTMLquot;
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
20. Why Architecture matters PHPCon Italia 2009
Single responsibility principle
• quot;if it generates XML then it should not generate HTMLquot;
• quot;if you want to serialize to xml do not create quot;toxmlquot;
Method, instead pass $this to the XMLExporterquot;
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
21. Why Architecture matters PHPCon Italia 2009
Success
• D.R.Y. == Do Not Repeat Yourself
• Single responsibility principle
• K.I.S.S.
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
22. Why Architecture matters PHPCon Italia 2009
K.I.S.S.
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
23. Why Architecture matters PHPCon Italia 2009
K.I.S.S.
• think in advance but don‘t think too complex
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
24. Why Architecture matters PHPCon Italia 2009
K.I.S.S.
• think in advance but don‘t think too complex
• before making any generalisation have at least two cases
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
25. Why Architecture matters PHPCon Italia 2009
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
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
29. Why Architecture matters PHPCon Italia 2009
Evolving Architecture
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
30. Why Architecture matters PHPCon Italia 2009
Evolving Architecture
• Y.A.G.N.I. == You Ain‘t Gonna Need it
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
31. Why Architecture matters PHPCon Italia 2009
Evolving Architecture
• Y.A.G.N.I. == You Ain‘t Gonna Need it
• Without refactoring there is no evolution
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
33. Why Architecture matters PHPCon Italia 2009
Bad smells?
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
34. Why Architecture matters PHPCon Italia 2009
Bad smells?
• Do maintenance cost keep increasing?
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
35. Why Architecture matters PHPCon Italia 2009
Bad smells?
• Do maintenance cost keep increasing?
• Simple features need too long to be implemented
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
36. Why Architecture matters PHPCon Italia 2009
Bad smells?
• Do maintenance cost keep increasing?
• Simple features need too long to be implemented
• Small changes ripple through your system
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
41. comments „what not why“
long methods
dead code
data classes
Freitag, 20. März 2009
42. Why Architecture matters PHPCon Italia 2009
Bad Smells
• http://martinfowler.com/bliki/CodeSmell.html
• http://www.codinghorror.com/blog/archives/000589.html
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
44. Why Architecture matters PHPCon Italia 2009
Layered Architecture
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
45. Why Architecture matters PHPCon Italia 2009
Layered Architecture
• separation of concerns
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
46. Why Architecture matters PHPCon Italia 2009
Layered Architecture
• separation of concerns
• If they can live without each other - why to couple them?
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
47. Why Architecture matters PHPCon Italia 2009
Layered Architecture
• separation of concerns
• If they can live without each other - why to couple them?
• Find the boundaries and cut mercilessly.
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
48. Why Architecture matters PHPCon Italia 2009
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!
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
49. Why Architecture matters PHPCon Italia 2009
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
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
50. Why Architecture matters PHPCon Italia 2009
SOA
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
51. Why Architecture matters PHPCon Italia 2009
SOA
• Pro: makes scaling very easy
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
52. Why Architecture matters PHPCon Italia 2009
SOA
• Pro: makes scaling very easy
• Pro: clear defined boundaries, no violations possible
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
53. Why Architecture matters PHPCon Italia 2009
SOA
• Pro: makes scaling very easy
• Pro: clear defined boundaries, no violations possible
• Pro: perfect for refactoring
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
54. Why Architecture matters PHPCon Italia 2009
SOA
• Pro: makes scaling very easy
• Pro: clear defined boundaries, no violations possible
• Pro: perfect for refactoring
• Pro: Deployment benefits
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
55. Why Architecture matters PHPCon Italia 2009
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
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
58. ZendDb
PDO
ADOdb
propel
Freitag, 20. März 2009
59. Why Architecture matters PHPCon Italia 2009
Database
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
60. Why Architecture matters PHPCon Italia 2009
Database
• you need a database access layer
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
61. Why Architecture matters PHPCon Italia 2009
Database
• you need a database access layer
• go ORM if possible (performance!)
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
62. Why Architecture matters PHPCon Italia 2009
Database
• you need a database access layer
• go ORM if possible (performance!)
• Active Record has business logic
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
63. Why Architecture matters PHPCon Italia 2009
Database
• you need a database access layer
• go ORM if possible (performance!)
• Active Record has business logic
• business layer - not abstraction layer
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
65. Db Abstraction Layer PDO, ADOdb, ZendDb....
Object Layer Table Data Gateway Pattern
Freitag, 20. März 2009
66. Db Abstraction Layer PDO, ADOdb, ZendDb....
Object Layer Table Data Gateway Pattern
Active Record
Business Layer
Freitag, 20. März 2009
67. Db Abstraction Layer PDO, ADOdb, ZendDb....
Object Layer Table Data Gateway Pattern
Active Record
Business Layer function giveMeMyData()
Freitag, 20. März 2009
69. Why Architecture matters PHPCon Italia 2009
Controller
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
70. Why Architecture matters PHPCon Italia 2009
Controller
• Common mistake: business logic in controller
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
71. Why Architecture matters PHPCon Italia 2009
Controller
• Common mistake: business logic in controller
• Keep it out! Otherwise you will end with SQL in controller
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
72. Why Architecture matters PHPCon Italia 2009
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
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
73. Why Architecture matters PHPCon Italia 2009
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!
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
74. Why Architecture matters PHPCon Italia 2009
View
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
75. Why Architecture matters PHPCon Italia 2009
View
• Use a template engine. Watch performance!
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
76. Why Architecture matters PHPCon Italia 2009
View
• Use a template engine. Watch performance!
• No business logic in the template/html
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
77. Why Architecture matters PHPCon Italia 2009
View
• Use a template engine. Watch performance!
• No business logic in the template/html
• Kick Ass!
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
85. Why Architecture matters PHPCon Italia 2009
Unit Tests
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
86. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
87. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
• do not touch:
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
88. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
• do not touch:
- database
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
89. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
• do not touch:
- database
- network
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
90. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
• do not touch:
- database
- network
- (files)
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
91. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
• do not touch:
- database
- network
- (files)
• use mocks/stubs
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
92. Why Architecture matters PHPCon Italia 2009
Unit Tests
• test a single class
• do not touch:
- database
- network
- (files)
• use mocks/stubs
• provide fast feedback
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
94. Why Architecture matters PHPCon Italia 2009
Integration Tests
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
95. Why Architecture matters PHPCon Italia 2009
Integration Tests
• test several classes
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
96. Why Architecture matters PHPCon Italia 2009
Integration Tests
• test several classes
• test communication between classes/modules
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
97. Why Architecture matters PHPCon Italia 2009
Integration Tests
• test several classes
• test communication between classes/modules
• they test full components
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
98. Acceptance Tests
Integration Tests
Unit Tests
Freitag, 20. März 2009
99. Why Architecture matters PHPCon Italia 2009
Acceptance Tests
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
100. Why Architecture matters PHPCon Italia 2009
Acceptance Tests
• test functionality from „outside“
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
101. Why Architecture matters PHPCon Italia 2009
Acceptance Tests
• test functionality from „outside“
• often build from „user stories“
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
102. Why Architecture matters PHPCon Italia 2009
Acceptance Tests
• test functionality from „outside“
• often build from „user stories“
• usually done with Selenium
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
103. what if fixture/mock preparation
are much larger than tests?
Freitag, 20. März 2009
104. what if your tests run for hours ?
Freitag, 20. März 2009
111. Why Architecture matters PHPCon Italia 2009
Thank you for your interest!
http://joind.in/talk/view/232
Lars Jankowfsky, swoodoo.com
Freitag, 20. März 2009