Beautiful Code with AOP and DIInternational PHP Conference – Frankfurt, Germany
CAUTION!HOT CODE
Overview  Background Information  Domain Driven Design  Components and  Dependecy Injection  Aspect Oriented Programming  ...
Background InformationMission "Ease of Use"    "Ease of Use" has been identified as the main topic for next    TYPO3 versio...
Background InformationCore + Extensions = TYPO3
Background InformationThree Sub-Projects       TYPO3 CMS         TYPO3 Fr amework   TYPO3 CR
Background InformationEmpty Canvas                         ?
Background Information(Some) Guiding Principles    anticipate real world needs    focus on the domain    centralize concer...
Background Information5 Development Methods                    Domain                 Driven Design                       ...
Domain Driven Design  A domain is the activity or business of the user  Domain Driven Design is about    focussing on the ...
Domain Driven DesignWhy focus on the Domain?Most time in development is spent oninfrastructure instead of user interfaces ...
Domain Driven DesignUbiquitous language    The common vocabulary is an important prerequisite    for successful collaborat...
Domain Driven DesignPhone Book Domain Model
Domain Driven DesignMore phone book actions    show phone book entries    check if user may delete phone book entry    exp...
✘Domain Driven DesignMore phone book actions    show phone book entries      not in                              domain   ...
Domain Driven DesignLayered Architecture                   View Presentation                   Controller                 ...
Domain Driven DesignLayered Architecture                   View Presentation                   Controller                 ...
Domain Driven DesignDomain-Driven Design       „Cancel the registration for Mr. Sarkosh“  $res = $DB->execQuery(SELECT cnu...
Domain Driven DesignDomain-Driven Design    „Cancel the registration for Mr. Sarkosh“    $customer = $this->customerReposi...
Components
ComponentsPlaying with building blocks    In TYPO3 5.0, objects considered as components    The combination of components ...
ComponentsComponent Dependencies    Components seldomly come alone    Components depend on other components which depend o...
ComponentsComponent Dependencies    Components seldomly come alone    Components depend on other components which depend o...
ComponentsComponent Dependencies    Possible solutions:      Factory pattern (GoF):      $event = EventFactory::createEven...
ComponentsDependency Injection    A component doesnt ask for the instance of another component    but gets it injected    ...
ComponentsPractical examples for DI    Example using ...      Constructor Injection      Setter Injection      Autowiring ...
Aspect Oriented Programming  AOP is a programming paradigm  complements OOP by separating concerns to improve  modularizat...
Aspect Oriented ProgrammingCross-cutting concerns                       Presentation                          Domain      ...
Aspect Oriented ProgrammingCross-cutting concerns                       Presentation   The concerns                       ...
Aspect Oriented ProgrammingCross-cutting concerns                      Event Domain Model                              Sec...
Aspect Oriented ProgrammingSome Definitions    Advice      encapsulated code, to be re-used    Joinpoint      places in th...
Aspect Oriented ProgrammingAspects in action                        Demo
Read before first useTry it yourself
Try it yourself(Advertising)     The TYPO3 Framework is the only PHP-based solution which     truly supports Domain Driven...
Try it yourselfInstallation     You need PHP6     Current installation options:        svn checkout http://5-0.dev.typo3.o...
Try it yourselfInstallation
When ...?
Recommended literature
Recommended literature             Eric Evans:             Domain Driven Design             Tackling Complexity in the Hea...
Recommended literature             Martin Fowler:             Patterns of Enterprise             Application Architecture ...
Recommended literature             Jimmy Nilsson:             Applying Domain-Driven             Design and Patterns      ...
Links  TYPO3 5.0 Subsite  http://typo3.org/gimmefive  TYPO3 5.0 Development Website  http://5-0.dev.typo3.org  TYPO3 5.0 Do...
So long and thanks for the fishQuestionsrobert@typo3.org
IPC07 Talk - Beautiful Code with AOP and DI
Upcoming SlideShare
Loading in …5
×

IPC07 Talk - Beautiful Code with AOP and DI

1,686 views

Published on

This presentation at the International PHP Conference 2007 in Frankfurt, Germany outlines the concepts of Domain Driven Design, supported by techniques such as Aspect Oriented Programming and Dependency Injection. A practical example was shown, using a recent snapshot of the upcoming FLOW3 Framework.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,686
On SlideShare
0
From Embeds
0
Number of Embeds
78
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

IPC07 Talk - Beautiful Code with AOP and DI

  1. 1. Beautiful Code with AOP and DIInternational PHP Conference – Frankfurt, Germany
  2. 2. CAUTION!HOT CODE
  3. 3. Overview Background Information Domain Driven Design Components and Dependecy Injection Aspect Oriented Programming TYPO3 Framework
  4. 4. Background InformationMission "Ease of Use" "Ease of Use" has been identified as the main topic for next TYPO3 versions First steps were founding the TYPO3 Association, building a brand and "zapping the Gremlins" Decision to rewrite TYPO3 based on a new architecture to achieve Ease of Use for developers Currently TYPO3 5.0 is being developed - the 4.x branch will still be improved and see new features
  5. 5. Background InformationCore + Extensions = TYPO3
  6. 6. Background InformationThree Sub-Projects TYPO3 CMS TYPO3 Fr amework TYPO3 CR
  7. 7. Background InformationEmpty Canvas ?
  8. 8. Background Information(Some) Guiding Principles anticipate real world needs focus on the domain centralize concerns convention over configuration human readable code modularity everywhere design decisions can be changed
  9. 9. Background Information5 Development Methods Domain Driven Design Dont Work where it matters (DDD) Repeat Yourself Test Driven Work where it belongs to (DRY) Development No chaos, ever (TDD) Continuous Dependency Injection Integration Aspect Orient Programming No bad surprises (CI) Graphical User Interface Innovation built-in (DI, AOP, GUI) ... and more XP techniques
  10. 10. Domain Driven Design A domain is the activity or business of the user Domain Driven Design is about focussing on the domain and domain logic accurately mapping the domain concepts to software forming a ubiquitous language among the project members
  11. 11. Domain Driven DesignWhy focus on the Domain?Most time in development is spent oninfrastructure instead of user interfaces andbusiness logic.We dont want that.
  12. 12. Domain Driven DesignUbiquitous language The common vocabulary is an important prerequisite for successful collaboration Use the same words for discussion, modeling, development and documentation
  13. 13. Domain Driven DesignPhone Book Domain Model
  14. 14. Domain Driven DesignMore phone book actions show phone book entries check if user may delete phone book entry export phone book entries log phone book actions
  15. 15. ✘Domain Driven DesignMore phone book actions show phone book entries not in domain check if user may delete phone book entry the export phone book entries of a phone log phone book actions book
  16. 16. Domain Driven DesignLayered Architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper (part of Content Repository) Data source Data Source Abstraction
  17. 17. Domain Driven DesignLayered Architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper (part of Content Repository) Data source Data Source Abstraction
  18. 18. Domain Driven DesignDomain-Driven Design „Cancel the registration for Mr. Sarkosh“ $res = $DB->execQuery(SELECT cnumber FROM customers WHERE lastname LIKE "Sarkosh"); if (!$res) throw new Exception; $c = mysql_fetch_assoc($res); if (!is_array($c)) throw new Exception; $res = $DB->execQuery(SELECT * FROM registrations WHERE cnumber = . intval($c[cnumber])); $reg = mysql_fetch_assoc($res); if (!is_array($reg)) { $this->log(Registration not found); throw new Exception; } if (!$reg[status] == 3) throw new Exception;
  19. 19. Domain Driven DesignDomain-Driven Design „Cancel the registration for Mr. Sarkosh“ $customer = $this->customerRepository->findByLastname(Sarkosh); $event = $this->eventRepository->getEvent(IPC07); $event->addParticipant($customer); $event->removeParticipant($customer); $customer = $this->customerRepository->findByLastname(Sarkosh); $event = $this->eventRepository->getEvent(IPC07); $registrationService->cancelRegistration($event, $customer);
  20. 20. Components
  21. 21. ComponentsPlaying with building blocks In TYPO3 5.0, objects considered as components The combination of components used is configurable (orchestration) The less components know about each other the easier it is to reuse them in a variety of contexts Create your own LEGO set by creating cleanly separated, decoupled components!
  22. 22. ComponentsComponent Dependencies Components seldomly come alone Components depend on other components which depend on other components which ... Inspiring people to share
  23. 23. ComponentsComponent Dependencies Components seldomly come alone Components depend on other components which depend on other components which ... Problem: Components explicitly refer to other components: $event = new Event(); Inspiring people to share
  24. 24. ComponentsComponent Dependencies Possible solutions: Factory pattern (GoF): $event = EventFactory::createEvent(); Registry pattern (Fowler) / Service Locator: class ServiceLocator { public function registerComponent($name, $component) {} public function getInstance($name); } Inspiring people to share
  25. 25. ComponentsDependency Injection A component doesnt ask for the instance of another component but gets it injected This a type of "Inversion of Control" also referred to as the "Hollywood Principle": "Dont call us, well call you" Enforces loose coupling and high cohesion Makes you a better programmer
  26. 26. ComponentsPractical examples for DI Example using ... Constructor Injection Setter Injection Autowiring Demo
  27. 27. Aspect Oriented Programming AOP is a programming paradigm complements OOP by separating concerns to improve modularization OOP modularizes concerns: methods, classes, packages AOP addresses cross-cutting concerns
  28. 28. Aspect Oriented ProgrammingCross-cutting concerns Presentation Domain Data source
  29. 29. Aspect Oriented ProgrammingCross-cutting concerns Presentation The concerns live here Domain Data source
  30. 30. Aspect Oriented ProgrammingCross-cutting concerns Event Domain Model Security CONCERNS Logging X-ING
  31. 31. Aspect Oriented ProgrammingSome Definitions Advice encapsulated code, to be re-used Joinpoint places in the code where advice can be applied Pointcut identifies set of joinpoints where advice should be applied Aspect groups advices and pointcuts
  32. 32. Aspect Oriented ProgrammingAspects in action Demo
  33. 33. Read before first useTry it yourself
  34. 34. Try it yourself(Advertising) The TYPO3 Framework is the only PHP-based solution which truly supports Domain Driven Design powerful, transparent and plain PHP-based AOP support (no extension required, no compile step) full-featured IoC container with Dependency Injection great (and big) community, backed by the TYPO3 Association ....
  35. 35. Try it yourselfInstallation You need PHP6 Current installation options: svn checkout http://5-0.dev.typo3.org/svn/TYPO3/ download the TYPO3 installer
  36. 36. Try it yourselfInstallation
  37. 37. When ...?
  38. 38. Recommended literature
  39. 39. Recommended literature Eric Evans: Domain Driven Design Tackling Complexity in the Heart of Software Addison Wesley 2002
  40. 40. Recommended literature Martin Fowler: Patterns of Enterprise Application Architecture Addison Wesley 2002
  41. 41. Recommended literature Jimmy Nilsson: Applying Domain-Driven Design and Patterns Addison Wesley 2006
  42. 42. Links TYPO3 5.0 Subsite http://typo3.org/gimmefive TYPO3 5.0 Development Website http://5-0.dev.typo3.org TYPO3 5.0 Documentation http://5-0.dev.typo3.org/guide
  43. 43. So long and thanks for the fishQuestionsrobert@typo3.org

×