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.
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
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
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);
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
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
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