symfony live 2010 - Using symfony events to create clean class interfaces

25,190 views

Published on

Published in: Technology, Business
1 Comment
23 Likes
Statistics
Notes
  • apple keynote :(
    missing a pdf or a openoffice format
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
25,190
On SlideShare
0
From Embeds
0
Number of Embeds
922
Actions
Shares
0
Downloads
306
Comments
1
Likes
23
Embeds 0
No embeds

No notes for slide
  • symfony live 2010 - Using symfony events to create clean class interfaces

    1. Using symfony events to create clean class interfaces by Dennis Benkert
    2. Dennis Who?! 2
    3. Dennis Who?! 2
    4. Dennis Who?! 2
    5. Dennis Who?! 2
    6. Dennis Who?! 2
    7. Agenda 3
    8. Agenda Code Coupling 3
    9. Agenda Code Coupling Event Basics 3
    10. Agenda Code Coupling Event Basics Events in Code 3
    11. Agenda Code Coupling Event Basics Events in Code Usage Examples 3
    12. Agenda Code Coupling Event Basics Events in Code Usage Examples Problems of Events 3
    13. Code Coupling 4
    14. In the beginning it‘s all so cleaned up... ... but over time things start to change 5
    15. „Coupling is the single greatest problem in large software systems“ - Ted Faison 6
    16. „You don‘t want to achieve consistency by making the classes tightly coupled, because that reduces their reuseability“ - Gang of Four 7
    17. Separation of Concerns 8
    18. Separation of Concerns 8
    19. Separation of Concerns 8
    20. Separation of Concerns 8
    21. Separation of Concerns 8
    22. Separation of Concerns 8
    23. Separation of Concerns 8
    24. Separation of Concerns 8
    25. Separation of Concerns 8
    26. Separation of Concerns Events, DI, ... 8
    27. Event Basics 9
    28. Event Connection Event Dispatcher Software Components 10
    29. Event Connection Event Dispatcher Software Components 10
    30. Event Connection Event Dispatcher connect (registration.complete) . Software Components 10
    31. Event Connection Event Dispatcher connect (registration.complete) . Software Components 10
    32. Event Connection Event Dispatcher connect connect (registration.complete) (registration.complete) . Software Components 10
    33. Basic Event Notification 11
    34. Basic Event Notification 11
    35. Basic Event Notification notify 11
    36. Basic Event Notification notify (registration.complete) 11
    37. Basic Event Notification notify (registration.complete) 11
    38. Basic Event Notification notify (registration.complete) notification 11
    39. Basic Event Notification notify (registration.complete) notification 11
    40. Basic Event Notification notify (registration.complete) notification 11
    41. Basic Event Notification notify (registration.complete) notification notification 11
    42. Basic Event Notification notify (registration.complete) notification notification 11
    43. More Event Notifications 12
    44. More Event Notifications 12
    45. More Event Notifications filter 12
    46. More Event Notifications filter (blog_post.render) 12
    47. More Event Notifications filter (blog_post.render) 12
    48. More Event Notifications filter (blog_post.render) notification 12
    49. More Event Notifications filter (blog_post.render) notification 12
    50. More Event Notifications filter (blog_post.render) notification 12
    51. More Event Notifications filter (blog_post.render) returnValue notification 12
    52. More Event Notifications filter (blog_post.render) returnValue notification 12
    53. More Event Notifications filter (blog_post.render) returnValue notification notification 12
    54. More Event Notifications filter (blog_post.render) returnValue notification notification 12
    55. More Event Notifications filter (blog_post.render) returnValue notification notification 12
    56. More Event Notifications filter (blog_post.render) returnValue returnValue notification notification 12
    57. More Event Notifications filter (blog_post.render) returnValue returnValue notification notification 12
    58. More Event Notifications returnValue filter (blog_post.render) returnValue returnValue notification notification 12
    59. More Event Notifications 13
    60. More Event Notifications 13
    61. More Event Notifications notifyUntil 13
    62. More Event Notifications notifyUntil (registration.complete) 13
    63. More Event Notifications notifyUntil (registration.complete) 13
    64. More Event Notifications notifyUntil (registration.complete) notification 13
    65. More Event Notifications notifyUntil (registration.complete) notification 13
    66. More Event Notifications notifyUntil (registration.complete) notification 13
    67. More Event Notifications notifyUntil (registration.complete) returnValue notification 13
    68. More Event Notifications notifyUntil (registration.complete) returnValue notification 13
    69. More Event Notifications returnValue notifyUntil (registration.complete) returnValue notification 13
    70. More Event Notifications returnValue notifyUntil (registration.complete) returnValue notification 13
    71. More Event Notifications returnValue notifyUntil (registration.complete) returnValue notification 13
    72. More Event Notifications returnValue notifyUntil (registration.complete) returnValue notification 13
    73. More Event Notifications returnValue notifyUntil (registration.complete) returnValue notification 13
    74. Events in Code 14
    75. Events in Code class frontendConfiguration extends sfApplicationConfiguration { public function configure() { $this->dispatcher->connect('registration.complete', array(SomeClass, 'listenToRegistrationComplete')); // [...] } } 15
    76. Events in Code class frontendConfiguration extends sfApplicationConfiguration { public function configure() { $this->dispatcher->connect('registration.complete', array(SomeClass, 'listenToRegistrationComplete')); // [...] } } 15
    77. Events in Code Event Name class frontendConfiguration extends sfApplicationConfiguration { public function configure() { $this->dispatcher->connect('registration.complete', array(SomeClass, 'listenToRegistrationComplete')); // [...] } } 15
    78. Events in Code Event Name class frontendConfiguration extends sfApplicationConfiguration { public function configure() { $this->dispatcher->connect('registration.complete', array(SomeClass, 'listenToRegistrationComplete')); // [...] } } 15
    79. Events in Code Event Name class frontendConfiguration extends sfApplicationConfiguration { public function configure() { $this->dispatcher->connect('registration.complete', array(SomeClass, 'listenToRegistrationComplete')); // [...] } } Callable (can be static or non-static) 15
    80. Events in Code $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); 16
    81. Events in Code $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); 16
    82. Events in Code Notification Type $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); 16
    83. Events in Code Notification Type $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); 16
    84. Events in Code Notification Type $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); Subject 16
    85. Events in Code Notification Type $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); Subject 16
    86. Events in Code Event Name Notification Type $this->dispatcher->notify(new sfEvent($user, 'registration.complete')); Subject 16
    87. Events in Code class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } 17
    88. Events in Code class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } 17
    89. Events in Code Registered Method (called via notfiy) class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } 17
    90. Events in Code Registered Method (called via notfiy) class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } 17
    91. Events in Code Registered Method (called via notfiy) class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } Event as Parameter 17
    92. Events in Code Registered Method (called via notfiy) class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } Event as Parameter 17
    93. Events in Code Registered Method (called via notfiy) class SomeClass { public static function listenToRegistrationComplete(sfEvent $event) { $user = $event->getSubject(); // [...] } } Passed Subject Event as Parameter 17
    94. Events in Code $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); 18
    95. Events in Code $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); 18
    96. Events in Code Notification Type $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); 18
    97. Events in Code Notification Type $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); 18
    98. Events in Code Notification Type $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); Raw Value 18
    99. Events in Code Notification Type $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); Raw Value 18
    100. Events in Code Notification Type $returnValue = $this->dispatcher->filter(new sfEvent($blogPost, 'blog_post.render'), $blogPost->getBody()); Filtered Value Raw Value 18
    101. Events in Code class MarkdownParser { // [...] public static function listenToRegistrationComplete(sfEvent $event, $body) { $markdownParser = new self(); $parsedBody = $markdownParser->parse($body); // [...] return $parsedBody; } } 19
    102. Events in Code class MarkdownParser { // [...] public static function listenToRegistrationComplete(sfEvent $event, $body) { $markdownParser = new self(); $parsedBody = $markdownParser->parse($body); // [...] return $parsedBody; } } 19
    103. Events in Code Raw Value as Parameter class MarkdownParser { // [...] public static function listenToRegistrationComplete(sfEvent $event, $body) { $markdownParser = new self(); $parsedBody = $markdownParser->parse($body); // [...] return $parsedBody; } } 19
    104. Events in Code Raw Value as Parameter class MarkdownParser { // [...] public static function listenToRegistrationComplete(sfEvent $event, $body) { $markdownParser = new self(); $parsedBody = $markdownParser->parse($body); // [...] return $parsedBody; } } 19
    105. Events in Code Raw Value as Parameter class MarkdownParser { // [...] public static function listenToRegistrationComplete(sfEvent $event, $body) { $markdownParser = new self(); $parsedBody = $markdownParser->parse($body); // [...] return $parsedBody; } } Filtered Value 19
    106. Usage Examples 20
    107. Other Usage Examples skoop 21
    108. Other Usage Examples Being able to add extra actions to specific functionality without having to alter the existing code. skoop 21
    109. Other Usage Examples snzapka 22
    110. Other Usage Examples I use events mostly with object states changes, for example to send email, notify someone, clear cache, calculate sth. snzapka 22
    111. Other Usage Examples b00giZm 23
    112. Other Usage Examples I have a centralized "spot" for file system operations. e.g. when a user deletes an image from the DB, it kicks off an event b00giZm 23
    113. Other Usage Examples helasliban 24
    114. Other Usage Examples Right now I'm using symfony events for loose coupling of symfony plugins. helasliban 24
    115. Other Usage Examples ubermuda 25
    116. Other Usage Examples Obfuscate code, totally screwing up the app's workflow with chain- binded useless events. o/ ubermuda 25
    117. Problems of Events 26
    118. Problems of Events No Silver Bullet 27
    119. Problems of Events No Silver Bullet Events won‘t help with every problem! 27
    120. Problems of Events Use Events for optional coupling 28
    121. Problems of Events Use Events for optional coupling If you need mandatory coupling use DI. 28
    122. Problems of Events No Notification Order 29
    123. Problems of Events No Notification Order If your listeners need ordering ure doin it rong! 29
    124. Problems of Events Harder debugging 30
    125. Problems of Events Harder debugging It can get complicated if you do weird things. 30
    126. Problems of Events Harder debugging It can get complicated if you do weird things. (Remember ubermuda) 30
    127. Problems of Events Real Setup Hardly Testable 31
    128. Problems of Events Real Setup Hardly Testable You can never know who connected to an event. 31
    129. Problems of Events Slowness 32
    130. Problems of Events Slowness Every firing starts the Events notification chain. 32
    131. Thank you! Give feedback on joind.in, please http://joind.in/talk/view/1415 33
    132. Credits Thanks to: - Bernhard and Andreas for the reviews and tips. - Konrad and Samim for the designs and the artworks. Creative Commons stuff used: - „Cog, Gear, Settings“ icon by „Visual Pharm“ - http://www.iconfinder.net/icondetails/27879/128/ - „Crying, Man“ icon by Rokey - http://www.iconfinder.net/icondetails/37613/128/ - „Box, Package“ icon by Alessandro Rei - http://www.iconfinder.net/icondetails/6507/128/ 34

    ×