modular application architecture - qafoo · confoo.ca 2012 tobias schlitt (@tobysen) march 2nd 2012...

120
Modular Application Architecture Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43

Upload: others

Post on 23-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Modular Application ArchitectureConfoo.ca 2012

Tobias Schlitt (@tobySen)

March 2nd 2012

Modular Application Architecture 1 / 43

Page 2: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

About me

I Degree in computer sienceI More than 10 years of professional PHPI Open source enthusiastsI Contributing to various FLOSS projects

Modular Application Architecture 2 / 43

Page 3: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

About me

I Degree in computer sienceI More than 10 years of professional PHPI Open source enthusiastsI Contributing to various FLOSS projects

Modular Application Architecture 2 / 43

Page 4: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

About me

I Degree in computer sienceI More than 10 years of professional PHPI Open source enthusiastsI Contributing to various FLOSS projects

Modular Application Architecture 2 / 43

Page 5: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Co-founder of

Qafoopassion for software quality

Modular Application Architecture 3 / 43

Page 6: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Co-founder of

Qafoopassion for software quality

Helping people to create high quality web applications.

Modular Application Architecture 3 / 43

Page 7: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Co-founder of

Qafoopassion for software quality

Helping people to create high quality web applications.

I Expert consultingI Individual trainingI . . .

I Software architectureI OO designI Quality assuranceI . . .

Modular Application Architecture 3 / 43

Page 8: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Co-founder of

Qafoopassion for software quality

Helping people to create high quality web applications.

I Expert consultingI Individual trainingI . . .

I Software architectureI OO designI Quality assuranceI . . .

Modular Application Architecture 3 / 43

Page 9: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Co-founder of

Qafoopassion for software quality

Helping people to create high quality web applications.

I Expert consultingI Individual trainingI . . .

I Software architectureI OO designI Quality assuranceI . . .

http://qafoo.com

Modular Application Architecture 3 / 43

Page 10: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Motivation

Resources

Approaches

Real world

Summary

Modular Application Architecture 4 / 43

Page 11: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Application

Application

Component Component Component

Modular Application Architecture 5 / 43

Page 12: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Modules

Application

Component Component Component

Module Module Module Module Module

Modular Application Architecture 6 / 43

Page 13: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Why modules?

I Need for customizationI Custom setup for customersI 3rd party extensions

I Develop modules seperately from main applicationI External developersI Seperate release cycles

I Slag the main applicationI Raise maintainability

Modular Application Architecture 7 / 43

Page 14: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Why modules?

I Need for customizationI Custom setup for customersI 3rd party extensions

I Develop modules seperately from main applicationI External developersI Seperate release cycles

I Slag the main applicationI Raise maintainability

Modular Application Architecture 7 / 43

Page 15: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Why modules?

I Need for customizationI Custom setup for customersI 3rd party extensions

I Develop modules seperately from main applicationI External developersI Seperate release cycles

I Slag the main applicationI Raise maintainability

Modular Application Architecture 7 / 43

Page 16: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Essential

Modular Application Architecture 8 / 43

Page 17: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Challenges

I Module structureI Registration / configurationI Handling ressourcesI Interaction with core

Modular Application Architecture 9 / 43

Page 18: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Challenges

I Module structure XI Registration / configurationI Handling ressourcesI Interaction with core

Modular Application Architecture 9 / 43

Page 19: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Challenges

I Module structure XI Registration / configuration XI Handling ressourcesI Interaction with core

Modular Application Architecture 9 / 43

Page 20: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Challenges

I Module structure XI Registration / configuration XI Handling ressources −→I Interaction with core

Modular Application Architecture 9 / 43

Page 21: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Challenges

I Module structure XI Registration / configuration XI Handling ressources −→I Interaction with core =⇒

Modular Application Architecture 9 / 43

Page 22: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Motivation

Resources

Approaches

Real world

Summary

Modular Application Architecture 10 / 43

Page 23: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Dealing with resources

I Typical module resourcesI TemplatesI TranslationsI ImagesI CSS

I Resources handled by code are “easy”I Register “overrides“

I Static file resources are notI Put modules in a web accessible path?I Copy / link static files to htdocs/?I Pipe static files through PHP?I Webserver configuration?

Modular Application Architecture 11 / 43

Page 24: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Dealing with resources

I Typical module resourcesI TemplatesI TranslationsI ImagesI CSS

I Resources handled by code are “easy”I Register “overrides“

I Static file resources are notI Put modules in a web accessible path?I Copy / link static files to htdocs/?I Pipe static files through PHP?I Webserver configuration?

Modular Application Architecture 11 / 43

Page 25: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Dealing with resources

I Typical module resourcesI TemplatesI TranslationsI ImagesI CSS

I Resources handled by code are “easy”I Register “overrides“

I Static file resources are notI Put modules in a web accessible path?I Copy / link static files to htdocs/?I Pipe static files through PHP?I Webserver configuration?

Modular Application Architecture 11 / 43

Page 26: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Motivation

Resources

Approaches

Real world

Summary

Modular Application Architecture 12 / 43

Page 27: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

ApproachesEvent handlingData handling

Modular Application Architecture 13 / 43

Page 28: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Event handling

I InteractionI Modules register for event typesI Events “fired” (by core or

module)I Registered modules informedI Maybe including dataI Optionally transparent

Application

Module

Module

Module

Event

Modular Application Architecture 14 / 43

Page 29: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Event handling

I InteractionI Modules register for event typesI Events “fired” (by core or

module)I Registered modules informedI Maybe including dataI Optionally transparent

Application

Module

Module

Module

Event

Modular Application Architecture 14 / 43

Page 30: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Event handling

I InteractionI Modules register for event typesI Events “fired” (by core or

module)I Registered modules informedI Maybe including dataI Optionally transparent

Application

Module

Module

Module

Event

Modular Application Architecture 14 / 43

Page 31: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Event handling

I InteractionI Modules register for event typesI Events “fired” (by core or

module)I Registered modules informedI Maybe including dataI Optionally transparent

Application

Module

Module

Module

Event

Modular Application Architecture 14 / 43

Page 32: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Event handling

I InteractionI Modules register for event typesI Events “fired” (by core or

module)I Registered modules informedI Maybe including dataI Optionally transparent

Application

Module

Module

Module

Event

Modular Application Architecture 14 / 43

Page 33: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Subject-Observer

1 <?php23 class Subject4 {

5 public function doSomething ( )6 {

7 $ th is −>n o t i f y ( ’ doSomethingStart ’ ) ;8 / / . . .9 $ th i s −>n o t i f y ( ’ doSomethingEnd ’ ) ;

10 }

11 }

Modular Application Architecture 15 / 43

Page 34: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Subject-Observer

1 <?php23 class Subject4 {

5 protected $observers = ar ray ( ) ;67 public function addObserver ( Observer $observer )8 {

9 $ th is −>observers [ ] = $observer ;10 }

1112 public function n o t i f y ( $event , $data = nul l )13 {

14 foreach ( $ th i s −>observers as $observer )15 {

16 $observer−>$event ( $data ) ;17 }

18 }

1920 public function doSomething ( )21 {

22 $ th is −>n o t i f y ( ’ doSomethingStart ’ ) ;23 / / . . .24 $ th is −>n o t i f y ( ’ doSomethingEnd ’ ) ;25 }

26 }

Modular Application Architecture 16 / 43

Page 35: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Subject-Observer

1 <?php23 class Subject4 {

5 protected $observers = ar ray ( ) ;67 public function addObserver ( Observer $observer )8 {

9 $ th is −>observers [ ] = $observer ;10 }

1112 public function n o t i f y ( $event , $data = nul l )13 {

14 foreach ( $ th i s −>observers as $observer )15 {

16 $observer−>$event ( $data ) ;17 }

18 }

1920 public function doSomething ( )21 {

22 $ th is −>n o t i f y ( ’ doSomethingStart ’ ) ;23 / / . . .24 $ th is −>n o t i f y ( ’ doSomethingEnd ’ ) ;25 }

26 }

Modular Application Architecture 16 / 43

Page 36: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Subject-Observer

1 <?php

3 class Observer4 {

5 public function doSomethingStart ( )6 {

7 / / . . .8 }

910 public function doSomethingEnd ( )11 {

12 / / . . .13 }

14 }

Modular Application Architecture 17 / 43

Page 37: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 38: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 39: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 40: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 41: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 42: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 43: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Transparent – any number of observers can registerI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structs

I Drawbacks:I Fully transparent – you have no idea how long a singal will

take to processI Limited to defined extension pointsI Requires implementation in each subject

Modular Application Architecture 18 / 43

Page 44: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Signal slot

1 <?php23 $handler = new S igna lS lo t ( ) ;45 $handler−> r e g i s t e r (6 ’ UserLoggedIn ’ ,7 ar ray ( new LoginCounterModule ( ) , ’ handleUserLoggedIn ’ )8 ) ;9 $handler−> r e g i s t e r (

10 ’ UserLoggedIn ’ ,11 ar ray ( new OnlineUsersModule ( ) , ’ updatedUserLis t ’ )12 ) ;1314 / / In l o g i n process15 $handler−>emit (16 ’ UserLoggedIn ’ ,17 new UserLoggedInData ( /∗ . . . ∗ / )18 ) ;

Modular Application Architecture 19 / 43

Page 45: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Signal slot

1 <?php23 $handler = new S igna lS lo t ( ) ;45 $handler−> r e g i s t e r (6 ’ UserLoggedIn ’ ,7 ar ray ( new LoginCounterModule ( ) , ’ handleUserLoggedIn ’ )8 ) ;9 $handler−> r e g i s t e r (

10 ’ UserLoggedIn ’ ,11 ar ray ( new OnlineUsersModule ( ) , ’ updatedUserLis t ’ )12 ) ;1314 / / In l o g i n process15 $handler−>emit (16 ’ UserLoggedIn ’ ,17 new UserLoggedInData ( /∗ . . . ∗ / )18 ) ;

Modular Application Architecture 19 / 43

Page 46: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Signal slot

1 <?php23 $handler = new S igna lS lo t ( ) ;45 $handler−> r e g i s t e r (6 ’ UserLoggedIn ’ ,7 ar ray ( new LoginCounterModule ( ) , ’ handleUserLoggedIn ’ )8 ) ;9 $handler−> r e g i s t e r (

10 ’ UserLoggedIn ’ ,11 ar ray ( new OnlineUsersModule ( ) , ’ updatedUserLis t ’ )12 ) ;1314 / / In l o g i n process15 $handler−>emit (16 ’ UserLoggedIn ’ ,17 new UserLoggedInData ( /∗ . . . ∗ / )18 ) ;

Modular Application Architecture 19 / 43

Page 47: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Signal slot

1 <?php23 $handler = new S igna lS lo t ( ) ;45 $handler−> r e g i s t e r (6 ’ UserLoggedIn ’ ,7 ar ray ( new LoginCounterModule ( ) , ’ handleUserLoggedIn ’ )8 ) ;9 $handler−> r e g i s t e r (

10 ’ UserLoggedIn ’ ,11 ar ray ( new OnlineUsersModule ( ) , ’ updatedUserLis t ’ )12 ) ;1314 / / In l o g i n process15 $handler−>emit (16 ’ UserLoggedIn ’ ,17 new UserLoggedInData ( /∗ . . . ∗ / )18 ) ;

Modular Application Architecture 19 / 43

Page 48: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 49: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 50: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 51: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 52: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 53: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 54: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 55: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Fully transparent – nobody needs to know who is calledI (Documented) clearly defined extension APII . . . optionally with clearly defined transmitted data structsI Can easily be made asynchronous

I Drawbacks:I Fully transparent – you have no idea how long a signal will

take to processI Limited to defined extension pointsI Signal-Slot handler needs to be injected

Modular Application Architecture 20 / 43

Page 56: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

ApproachesEvent handlingData handling

Modular Application Architecture 21 / 43

Page 57: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Data handling

I Data processingI Pipes

I Transport dataI Filters

I Manipulate data

Filter 3

Filter 2

Filter 1

Data

Data

Pipe

Pipe

Modular Application Architecture 22 / 43

Page 58: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Data handling

I Data processingI Pipes

I Transport dataI Filters

I Manipulate data

Filter 3

Filter 2

Filter 1

Data

Data

Pipe

Pipe

Modular Application Architecture 22 / 43

Page 59: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Data handling

I Data processingI Pipes

I Transport dataI Filters

I Manipulate data

Filter 3

Filter 2

Filter 1

Data

Data

Pipe

Pipe

Modular Application Architecture 22 / 43

Page 60: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Popoon

1 <?xml version= ” 1.0 ” ?>23 <sitemap xmlns= ” h t t p : / / apache . org / cocoon / sitemap / 1 . 0 ”>45 <p i p e l i n e s>67 <p i p e l i n e>8 <match type= ” u r i ” pa t t e rn = ” examples . tgz ”>9 <read type= ” tgz ” src= ” . ” name= ” examples . tgz ” />

10 < / match>11 < / p i p e l i n e>1213 <p i p e l i n e >14 <generate type= ” x m l f i l e ” s rc= ” examples . xml ” />15 < t rans form type= ” l i b x s l t ” s rc= ” examples . x s l ” />16 < s e r i a l i z e type= ” html ” />17 < / p i p e l i n e>1819 < / p i p e l i n e s>2021 < / sitemap>

Modular Application Architecture 23 / 43

Page 61: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Popoon

1 <?xml version= ” 1.0 ” ?>23 <sitemap xmlns= ” h t t p : / / apache . org / cocoon / sitemap / 1 . 0 ”>45 <p i p e l i n e s>67 <p i p e l i n e>8 <match type= ” u r i ” pa t t e rn = ” examples . tgz ”>9 <read type= ” tgz ” src= ” . ” name= ” examples . tgz ” />

10 < / match>11 < / p i p e l i n e>1213 <p i p e l i n e >14 <generate type= ” x m l f i l e ” s rc= ” examples . xml ” />15 < t rans form type= ” l i b x s l t ” s rc= ” examples . x s l ” />16 < s e r i a l i z e type= ” html ” />17 < / p i p e l i n e>1819 < / p i p e l i n e s>2021 < / sitemap>

Modular Application Architecture 23 / 43

Page 62: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Popoon

1 <?xml version= ” 1.0 ” ?>23 <sitemap xmlns= ” h t t p : / / apache . org / cocoon / sitemap / 1 . 0 ”>45 <p i p e l i n e s>67 <p i p e l i n e>8 <match type= ” u r i ” pa t t e rn = ” examples . tgz ”>9 <read type= ” tgz ” src= ” . ” name= ” examples . tgz ” />

10 < / match>11 < / p i p e l i n e>1213 <p i p e l i n e >14 <generate type= ” x m l f i l e ” s rc= ” examples . xml ” />15 < t rans form type= ” l i b x s l t ” s rc= ” examples . x s l ” />16 < s e r i a l i z e type= ” html ” />17 < / p i p e l i n e>1819 < / p i p e l i n e s>2021 < / sitemap>

Modular Application Architecture 23 / 43

Page 63: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Popoon

1 <?xml version= ” 1.0 ” ?>23 <sitemap xmlns= ” h t t p : / / apache . org / cocoon / sitemap / 1 . 0 ”>45 <p i p e l i n e s>67 <p i p e l i n e>8 <match type= ” u r i ” pa t t e rn = ” examples . tgz ”>9 <read type= ” tgz ” src= ” . ” name= ” examples . tgz ” />

10 < / match>11 < / p i p e l i n e>1213 <p i p e l i n e >14 <generate type= ” x m l f i l e ” s rc= ” examples . xml ” />15 < t rans form type= ” l i b x s l t ” s rc= ” examples . x s l ” />16 < s e r i a l i z e type= ” html ” />17 < / p i p e l i n e>1819 < / p i p e l i n e s>2021 < / sitemap>

Modular Application Architecture 23 / 43

Page 64: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Popoon

1 <?xml version= ” 1.0 ” ?>23 <sitemap xmlns= ” h t t p : / / apache . org / cocoon / sitemap / 1 . 0 ”>45 <p i p e l i n e s>67 <p i p e l i n e>8 <match type= ” u r i ” pa t t e rn = ” examples . tgz ”>9 <read type= ” tgz ” src= ” . ” name= ” examples . tgz ” />

10 < / match>11 < / p i p e l i n e>1213 <p i p e l i n e >14 <generate type= ” x m l f i l e ” s rc= ” examples . xml ” />15 < t rans form type= ” l i b x s l t ” s rc= ” examples . x s l ” />16 < s e r i a l i z e type= ” html ” />17 < / p i p e l i n e>1819 < / p i p e l i n e s>2021 < / sitemap>

Modular Application Architecture 23 / 43

Page 65: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Clean architectural approachI Might gain high re-usability

I Drawbacks:I Filters might break data easilyI Somewhat forces linear code flow

Modular Application Architecture 24 / 43

Page 66: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Clean architectural approachI Might gain high re-usability

I Drawbacks:I Filters might break data easilyI Somewhat forces linear code flow

Modular Application Architecture 24 / 43

Page 67: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Clean architectural approachI Might gain high re-usability

I Drawbacks:I Filters might break data easilyI Somewhat forces linear code flow

Modular Application Architecture 24 / 43

Page 68: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Clean architectural approachI Might gain high re-usability

I Drawbacks:I Filters might break data easilyI Somewhat forces linear code flow

Modular Application Architecture 24 / 43

Page 69: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Clean architectural approachI Might gain high re-usability

I Drawbacks:I Filters might break data easilyI Somewhat forces linear code flow

Modular Application Architecture 24 / 43

Page 70: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Motivation

Resources

Approaches

Real world

Summary

Modular Application Architecture 25 / 43

Page 71: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Real worldHooksPatchingInheritance

Modular Application Architecture 26 / 43

Page 72: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook announcement

1 <?php23 / / . . . i n CSS render ing code . . .45 / / $out i s CSS s t r i n g6 s e r e n d i p i t y p l u g i n a p i : : hook event ( ’ css ’ , $out ) ;78 echo $out ;

Modular Application Architecture 27 / 43

Page 73: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook announcement

1 <?php23 / / . . . i n CSS render ing code . . .45 / / $out i s CSS s t r i n g6 s e r e n d i p i t y p l u g i n a p i : : hook event ( ’ css ’ , $out ) ;78 echo $out ;

Modular Application Architecture 27 / 43

Page 74: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook reaction

1 class serend ip i t y even t bbcode extends s e r e n d i p i t y e v e n t2 {

3 function event hook ( $event , &$bag , &$eventData ) {4 switch ( $event ) {5 case ’ css ’ :6 i f ( s t rpos ( $eventData , ’ . bb−code ’ ) !== fa lse ) {7 / / c lass e x i s t s i n CSS . . .8 return true ;9 }

10 ?>11 . bb−quote , . bb−code , . bb−php , . bb−code− t i t l e , . bb−php− t i t l e {

12 margin− l e f t : 20px ;13 margin− r i g h t : 20px ;14 /∗ . . . ∗ /15 }

16 /∗ . . . ∗ /17 <?php18 return true ;19 break ;2021 defaul t :22 return fa lse ;23 }

24 }

25 }

Modular Application Architecture 28 / 43

Page 75: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook reaction

1 class serend ip i t y even t bbcode extends s e r e n d i p i t y e v e n t2 {

3 function event hook ( $event , &$bag , &$eventData ) {4 switch ( $event ) {5 case ’ css ’ :6 i f ( s t rpos ( $eventData , ’ . bb−code ’ ) !== fa lse ) {7 / / c lass e x i s t s i n CSS . . .8 return true ;9 }

10 ?>11 . bb−quote , . bb−code , . bb−php , . bb−code− t i t l e , . bb−php− t i t l e {

12 margin− l e f t : 20px ;13 margin− r i g h t : 20px ;14 /∗ . . . ∗ /15 }

16 /∗ . . . ∗ /17 <?php18 return true ;19 break ;2021 defaul t :22 return fa lse ;23 }

24 }

25 }

Modular Application Architecture 28 / 43

Page 76: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook reaction

1 class serend ip i t y even t bbcode extends s e r e n d i p i t y e v e n t2 {

3 function event hook ( $event , &$bag , &$eventData ) {4 switch ( $event ) {5 case ’ css ’ :6 i f ( s t rpos ( $eventData , ’ . bb−code ’ ) !== fa lse ) {7 / / c lass e x i s t s i n CSS . . .8 return true ;9 }

10 ?>11 . bb−quote , . bb−code , . bb−php , . bb−code− t i t l e , . bb−php− t i t l e {

12 margin− l e f t : 20px ;13 margin− r i g h t : 20px ;14 /∗ . . . ∗ /15 }

16 /∗ . . . ∗ /17 <?php18 return true ;19 break ;2021 defaul t :22 return fa lse ;23 }

24 }

25 }

Modular Application Architecture 28 / 43

Page 77: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook reaction

1 class serend ip i t y even t bbcode extends s e r e n d i p i t y e v e n t2 {

3 function event hook ( $event , &$bag , &$eventData ) {4 switch ( $event ) {5 case ’ css ’ :6 i f ( s t rpos ( $eventData , ’ . bb−code ’ ) !== fa lse ) {7 / / c lass e x i s t s i n CSS . . .8 return true ;9 }

10 ?>11 . bb−quote , . bb−code , . bb−php , . bb−code− t i t l e , . bb−php− t i t l e {

12 margin− l e f t : 20px ;13 margin− r i g h t : 20px ;14 /∗ . . . ∗ /15 }

16 /∗ . . . ∗ /17 <?php18 return true ;19 break ;2021 defaul t :22 return fa lse ;23 }

24 }

25 }

Modular Application Architecture 28 / 43

Page 78: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook reaction

1 class serend ip i t y even t bbcode extends s e r e n d i p i t y e v e n t2 {

3 function event hook ( $event , &$bag , &$eventData ) {4 switch ( $event ) {5 case ’ css ’ :6 i f ( s t rpos ( $eventData , ’ . bb−code ’ ) !== fa lse ) {7 / / c lass e x i s t s i n CSS . . .8 return true ;9 }

10 ?>11 . bb−quote , . bb−code , . bb−php , . bb−code− t i t l e , . bb−php− t i t l e {

12 margin− l e f t : 20px ;13 margin− r i g h t : 20px ;14 /∗ . . . ∗ /15 }

16 /∗ . . . ∗ /17 <?php18 return true ;19 break ;2021 defaul t :22 return fa lse ;23 }

24 }

25 }

Modular Application Architecture 28 / 43

Page 79: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Serendipity hook reaction

1 class serend ip i t y even t bbcode extends s e r e n d i p i t y e v e n t2 {

3 function event hook ( $event , &$bag , &$eventData ) {4 switch ( $event ) {5 case ’ css ’ :6 i f ( s t rpos ( $eventData , ’ . bb−code ’ ) !== fa lse ) {7 / / c lass e x i s t s i n CSS . . .8 return true ;9 }

10 ?>11 . bb−quote , . bb−code , . bb−php , . bb−code− t i t l e , . bb−php− t i t l e {

12 margin− l e f t : 20px ;13 margin− r i g h t : 20px ;14 /∗ . . . ∗ /15 }

16 /∗ . . . ∗ /17 <?php18 return true ;19 break ;2021 defaul t :22 return fa lse ;23 }

24 }

25 }

Modular Application Architecture 28 / 43

Page 80: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I High flexibilityI Low coding efforts

I Drawbacks:I Plugin can easily break hook dataI No defined data formatsI “Liskov substitution principle” limits what you are allowed to do

Modular Application Architecture 29 / 43

Page 81: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I High flexibilityI Low coding efforts

I Drawbacks:I Plugin can easily break hook dataI No defined data formatsI “Liskov substitution principle” limits what you are allowed to do

Modular Application Architecture 29 / 43

Page 82: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I High flexibilityI Low coding efforts

I Drawbacks:I Plugin can easily break hook dataI No defined data formatsI “Liskov substitution principle” limits what you are allowed to do

Modular Application Architecture 29 / 43

Page 83: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I High flexibilityI Low coding efforts

I Drawbacks:I Plugin can easily break hook dataI No defined data formatsI “Liskov substitution principle” limits what you are allowed to do

Modular Application Architecture 29 / 43

Page 84: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I High flexibilityI Low coding efforts

I Drawbacks:I Plugin can easily break hook dataI No defined data formatsI “Liskov substitution principle” limits what you are allowed to do

Modular Application Architecture 29 / 43

Page 85: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I High flexibilityI Low coding efforts

I Drawbacks:I Plugin can easily break hook dataI No defined data formatsI “Liskov substitution principle” limits what you are allowed to do

Modular Application Architecture 29 / 43

Page 86: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Real worldHooksPatchingInheritance

Modular Application Architecture 30 / 43

Page 87: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Patching the source

I The naive approachI Works suprisingly well

I For some of the largest module ecosystemsI phpBB

Modular Application Architecture 31 / 43

Page 88: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Patching the source

I The naive approachI Works suprisingly well

I For some of the largest module ecosystemsI phpBB

Modular Application Architecture 31 / 43

Page 89: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

phpBB MODx format

1 <?xml version= ” 1.0 ” encoding= ” u t f −8” standalone= ” yes ” ?>2 < !−− . . . −−>3 <mod xmlns= ” h t t p : / /www. phpbb . com/ mods / xml / modx−1 .2 .0 . xsd ”>4 <header>< !−− . . . −−>< / header>5 < !−− . . . −−>6 <open src= ” index . php ”>7 <e d i t>8 <comment lang= ” en ”>Here i s a comment< / comment>9 <comment lang= ” n l ”>Hier i s een s t u k j e commentaar< / comment>

10 < f i n d> t e x t to f i n d< / f i n d>11 <ac t i on type= ” replace−wi th ”> t e x t to be replaced wi th< / ac t i on>12 < / e d i t>13 <e d i t>14 < f i n d> t e x t to f i n d< / f i n d>15 <ac t i on type= ” a f t e r −add ”> t e x t to be added on the l i n e a f t e r< / ac t i on>16 < / e d i t>17 < !−− . . . −−>18 < / open>19 < !−− . . . −−>20 < /mod>

Modular Application Architecture 32 / 43

Page 90: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

phpBB MODx format

1 <?xml version= ” 1.0 ” encoding= ” u t f −8” standalone= ” yes ” ?>2 < !−− . . . −−>3 <mod xmlns= ” h t t p : / /www. phpbb . com/ mods / xml / modx−1 .2 .0 . xsd ”>4 <header>< !−− . . . −−>< / header>5 < !−− . . . −−>6 <open src= ” index . php ”>7 <e d i t>8 <comment lang= ” en ”>Here i s a comment< / comment>9 <comment lang= ” n l ”>Hier i s een s t u k j e commentaar< / comment>

10 < f i n d> t e x t to f i n d< / f i n d>11 <ac t i on type= ” replace−wi th ”> t e x t to be replaced wi th< / ac t i on>12 < / e d i t>13 <e d i t>14 < f i n d> t e x t to f i n d< / f i n d>15 <ac t i on type= ” a f t e r −add ”> t e x t to be added on the l i n e a f t e r< / ac t i on>16 < / e d i t>17 < !−− . . . −−>18 < / open>19 < !−− . . . −−>20 < /mod>

Modular Application Architecture 32 / 43

Page 91: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

phpBB MODx format

1 <?xml version= ” 1.0 ” encoding= ” u t f −8” standalone= ” yes ” ?>2 < !−− . . . −−>3 <mod xmlns= ” h t t p : / /www. phpbb . com/ mods / xml / modx−1 .2 .0 . xsd ”>4 <header>< !−− . . . −−>< / header>5 < !−− . . . −−>6 <open src= ” index . php ”>7 <e d i t>8 <comment lang= ” en ”>Here i s a comment< / comment>9 <comment lang= ” n l ”>Hier i s een s t u k j e commentaar< / comment>

10 < f i n d> t e x t to f i n d< / f i n d>11 <ac t i on type= ” replace−wi th ”> t e x t to be replaced wi th< / ac t i on>12 < / e d i t>13 <e d i t>14 < f i n d> t e x t to f i n d< / f i n d>15 <ac t i on type= ” a f t e r −add ”> t e x t to be added on the l i n e a f t e r< / ac t i on>16 < / e d i t>17 < !−− . . . −−>18 < / open>19 < !−− . . . −−>20 < /mod>

Modular Application Architecture 32 / 43

Page 92: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

phpBB MODx format

1 <?xml version= ” 1.0 ” encoding= ” u t f −8” standalone= ” yes ” ?>2 < !−− . . . −−>3 <mod xmlns= ” h t t p : / /www. phpbb . com/ mods / xml / modx−1 .2 .0 . xsd ”>4 <header>< !−− . . . −−>< / header>5 < !−− . . . −−>6 <open src= ” index . php ”>7 <e d i t>8 <comment lang= ” en ”>Here i s a comment< / comment>9 <comment lang= ” n l ”>Hier i s een s t u k j e commentaar< / comment>

10 < f i n d> t e x t to f i n d< / f i n d>11 <ac t i on type= ” replace−wi th ”> t e x t to be replaced wi th< / ac t i on>12 < / e d i t>13 <e d i t>14 < f i n d> t e x t to f i n d< / f i n d>15 <ac t i on type= ” a f t e r −add ”> t e x t to be added on the l i n e a f t e r< / ac t i on>16 < / e d i t>17 < !−− . . . −−>18 < / open>19 < !−− . . . −−>20 < /mod>

Modular Application Architecture 32 / 43

Page 93: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Trivial to get started with (high “hackability”)I You can change anything

I Drawbacks:I Will definitely breakI Can lead to unparsable codeI Complex modules require deep knowledge

Modular Application Architecture 33 / 43

Page 94: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Trivial to get started with (high “hackability”)I You can change anything

I Drawbacks:I Will definitely breakI Can lead to unparsable codeI Complex modules require deep knowledge

Modular Application Architecture 33 / 43

Page 95: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Trivial to get started with (high “hackability”)I You can change anything

I Drawbacks:I Will definitely breakI Can lead to unparsable codeI Complex modules require deep knowledge

Modular Application Architecture 33 / 43

Page 96: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Trivial to get started with (high “hackability”)I You can change anything

I Drawbacks:I Will definitely breakI Can lead to unparsable codeI Complex modules require deep knowledge

Modular Application Architecture 33 / 43

Page 97: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Trivial to get started with (high “hackability”)I You can change anything

I Drawbacks:I Will definitely breakI Can lead to unparsable codeI Complex modules require deep knowledge

Modular Application Architecture 33 / 43

Page 98: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I Trivial to get started with (high “hackability”)I You can change anything

I Drawbacks:I Will definitely breakI Can lead to unparsable codeI Complex modules require deep knowledge

Modular Application Architecture 33 / 43

Page 99: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Real worldHooksPatchingInheritance

Modular Application Architecture 34 / 43

Page 100: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Inheritance

I Generally:I Use Aggregation for code re-useI Not inheritance!

I Oxid eSales (OS shop software)I Interesting extension modelI Built entirely on inheritanceI Each module can inherit from “any” classI Each inheriting class will be used everywhereI How can that be possible?

Modular Application Architecture 35 / 43

Page 101: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Inheritance

I Generally:I Use Aggregation for code re-useI Not inheritance!

I Oxid eSales (OS shop software)I Interesting extension modelI Built entirely on inheritanceI Each module can inherit from “any” classI Each inheriting class will be used everywhereI How can that be possible?

Modular Application Architecture 35 / 43

Page 102: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Inheritance

I Generally:I Use Aggregation for code re-useI Not inheritance!

I Oxid eSales (OS shop software)I Interesting extension modelI Built entirely on inheritanceI Each module can inherit from “any” classI Each inheriting class will be used everywhereI How can that be possible?

Modular Application Architecture 35 / 43

Page 103: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Inheritance

I Generally:I Use Aggregation for code re-useI Not inheritance!

I Oxid eSales (OS shop software)I Interesting extension modelI Built entirely on inheritanceI Each module can inherit from “any” classI Each inheriting class will be used everywhereI How can that be possible?

Modular Application Architecture 35 / 43

Page 104: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Inheritance

I Generally:I Use Aggregation for code re-useI Not inheritance!

I Oxid eSales (OS shop software)I Interesting extension modelI Built entirely on inheritanceI Each module can inherit from “any” classI Each inheriting class will be used everywhereI How can that be possible?

Modular Application Architecture 35 / 43

Page 105: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Modular inheritance

I oxnew("ClassName") instead of new ClassNameI Inheritance graph created on-the-flyI Generates intermediate classes

Modular Application Architecture 36 / 43

Page 106: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Example

1 <?php23 class o x A r t i c l e4 {

5 public function c a l c u l a t e P r i c e ( )6 {

7 / / . . .8 }

9 }

1011 class myAr t i c le12 extends o x A r t i c l e13 {

14 / / . . .15 }

1617 class y o u r A r t i c l e18 extends o x A r t i c l e19 {

20 / / . . .21 }

oxArticle

myArticle

yourArticle

Modular Application Architecture 37 / 43

Page 107: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Example

1 <?php23 class o x A r t i c l e4 {

5 public function c a l c u l a t e P r i c e ( )6 {

7 / / . . .8 }

9 }

1011 class myAr t i c le12 extends myAr t i c l e pa ren t13 {

14 / / . . .15 }

1617 class y o u r A r t i c l e18 extends y o u r A r t i c l e p a r e n t19 {

20 / / . . .21 }

oxArticle

myArticle

yourArticle

myArticle_p

yourArticle_p

Modular Application Architecture 38 / 43

Page 108: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Example

1 <?php23 class o x A r t i c l e4 {

5 public function c a l c u l a t e P r i c e ( )6 {

7 / / . . .8 }

9 }

1011 class myAr t i c le12 extends myAr t i c l e pa ren t13 {

14 / / . . .15 }

1617 class y o u r A r t i c l e18 extends y o u r A r t i c l e p a r e n t19 {

20 / / . . .21 }

oxArticle

myArticle

yourArticle

myArticle_p

yourArticle_p

Modular Application Architecture 38 / 43

Page 109: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 110: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 111: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 112: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 113: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 114: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 115: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 116: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Pro & Contra

I Benefits:I You can extend about everything. . .

I Drawbacks:I About everything will be extended. . .I You may not use the new operatorI Violates object-oriented design principlesI Non-enforcable constraints (parent::method())I Almost untestableI Everything becomes public API

Modular Application Architecture 39 / 43

Page 117: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Outline

Motivation

Resources

Approaches

Real world

Summary

Modular Application Architecture 40 / 43

Page 118: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Summary

I PatchingI HooksI Pipes & FiltersI InheritanceI Subject-ObserverI Signal-Slot

Modular Application Architecture 41 / 43

Page 119: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Thanks for Listening

Questions? Comments? Critics? Ideas?Please rate this talk at

https://joind.in/6102

Modular Application Architecture 42 / 43

Page 120: Modular Application Architecture - Qafoo · Confoo.ca 2012 Tobias Schlitt (@tobySen) March 2nd 2012 Modular Application Architecture 1 / 43. About me I Degree in computer sience I

Thanks for Listening

Please rate this talk athttps://joind.in/6102

(Slides will be linked there)

Stay in touchI Tobias SchlittI [email protected] @tobySen / @qafoo

Rent a PHP quality expert:http://qafoo.com

Modular Application Architecture 43 / 43