IPC07 Talk - Beautiful Code with AOP and DI

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 1 Group

    IPC07 Talk - Beautiful Code with AOP and DI - Presentation Transcript

    1. Beautiful Code with AOP and DI International PHP Conference – Frankfurt, Germany
    2. CAUTION! HOT CODE
    3. Overview Background Information Domain Driven Design Components and Dependecy Injection Aspect Oriented Programming TYPO3 Framework
    4. Background Information Mission \"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. Background Information Core + Extensions = TYPO3
    6. Background Information Three Sub-Projects TYPO3 CMS TYPO3 Fr amework TYPO3 CR
    7. Background Information Empty Canvas ?
    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. Background Information 5 Development Methods Domain Driven Design Don't 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. 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. Domain Driven Design Why focus on the Domain? Most time in development is spent on infrastructure instead of user interfaces and business logic. We don't want that.
    12. Domain Driven Design Ubiquitous language The common vocabulary is an important prerequisite for successful collaboration Use the same words for discussion, modeling, development and documentation
    13. Domain Driven Design Phone Book Domain Model
    14. Domain Driven Design More phone book actions show phone book entries check if user may delete phone book entry export phone book entries log phone book actions
    15. ✘ Domain Driven Design More 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. Domain Driven Design Layered 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. Domain Driven Design Layered 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. Domain Driven Design Domain-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. Domain Driven Design Domain-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. Components
    21. Components Playing 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. Components Component Dependencies Components seldomly come alone Components depend on other components which depend on other components which ... Inspiring people to share
    23. Components Component 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. Components Component 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. Components Dependency Injection A component doesn't 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\": \"Don't call us, we'll call you\" Enforces loose coupling and high cohesion Makes you a better programmer
    26. Components Practical examples for DI Example using ... Constructor Injection Setter Injection Autowiring Demo
    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. Aspect Oriented Programming Cross-cutting concerns Presentation Domain Data source
    29. Aspect Oriented Programming Cross-cutting concerns Presentation The concerns live here Domain Data source
    30. Aspect Oriented Programming Cross-cutting concerns Event Domain Model Security CONCERNS Logging X-ING
    31. Aspect Oriented Programming Some 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. Aspect Oriented Programming Aspects in action Demo
    33. Read before first use Try it yourself
    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. Try it yourself Installation You need PHP6 Current installation options: svn checkout http://5-0.dev.typo3.org/svn/TYPO3/ download the TYPO3 installer
    36. Try it yourself Installation
    37. When ...?
    38. Recommended literature
    39. Recommended literature Eric Evans: Domain Driven Design Tackling Complexity in the Heart of Software Addison Wesley 2002
    40. Recommended literature Martin Fowler: Patterns of Enterprise Application Architecture Addison Wesley 2002
    41. Recommended literature Jimmy Nilsson: Applying Domain-Driven Design and Patterns Addison Wesley 2006
    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. So long and thanks for the fish Questions robert@typo3.org

    + Robert LemkeRobert Lemke, 2 years ago

    custom

    2093 views, 1 favs, 2 embeds more stats

    This presentation at the International PHP Conferen more

    More info about this document

    CC Attribution License

    Go to text version

    • Total Views 2093
      • 1743 on SlideShare
      • 350 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 32
    Most viewed embeds
    • 349 views on http://flow3.typo3.org
    • 1 views on http://192.168.10.100

    more

    All embeds
    • 349 views on http://flow3.typo3.org
    • 1 views on http://192.168.10.100

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events