1. How to have your
domain-driven design cake
and eat it, too
Dan Haywood
22 Feb 2010
v
2. About me…
Involved with Naked Objects since 2002
Committer to the open source framework
lead developer of a number of sister projects
Author,"Domain Driven Design using Naked
Objects"
pragmatic bookshelf
Senior advisor to the Irish Government
technical advisor, domain modelling
coaching on agile development practices
v Page 2
3. Domain Driven Design
Ubiquitous Language
With a conscious effort by the team, the
domain model can provide the backbone
for that common language
Eric Evans
v Page 3
4. Roll Call
Who's read Eric Evans' book,
Domain-Driven design?
Who's practicising DDD?
Who's using an ORM?
Who's using agile methods?
v Page 4
5. What Is Naked Objects?
A Principle
behaviorally complete objects
An Architectural Pattern
automatically renders domain objects in an OOUI
A Framework
Open source, extensible
Rapid prototyping & development
Build webapps or rich client (client/server)
A bed-fellow for Domain-Driven Design
v Page 5
6. Naked Objects Pattern
Business functionality is
encapsulated on the
core business objects
Objects are exposed
directly & automatically
All user actions consist of
creating or retrieving objects,
forming associations between them
invoking actions on them
v Page 6
7. The DRY Principle
The UI representations
correspond directly
with the underlying
domain object model
objects and their icons
object properties / collections
the menu items available on an object
eg Claim#submit(Approver)
desktop icons with repositories / domain services
eg ClaimRepository, EmployeeRepository
v Page 7
8. A simple domain model...
0..1
Approver
*
Claim
Claimant Claim
Repository
*
*
Employee Claim
Employee
Repository Item
v
9. Naked Objects apps are just pojos
0..1
Approver
*
Claim
Claimant Claim
Repository
*
*
Employee Claim
Employee
Repository Item
v
10. But what does a Naked Objects
system look like?
Let's see...
v Page 10
11. The Naked Objects
Programming Model
• Dependency injection
Runtime support • Bytecode enhancements
• Declarative business rules
Annotations • Rendering hints
• see it
Business Rules • use it
through Conventions • do it
• know-whats
Behaviorally • know-how-tos
Complete • contributed actions
• Entity
Pojo • Value
• Repository & Services
Page 11
v
13. Run as webapp or client/server
Web app Client/server
Context Listener to Stateless server-side
bootstrap NOF architecture
ServletFilter to setup By default, actions
session invoked server-side
Host HTML viewer, @ExecutedOn overrides
Scimpi, Restful, Remoting either via plain
server-side remoting sockets or http
Transparent lazy loading
of resources
v
14. Pluggable Persistence
In-memory object store
use composite fixtures
XML object store
for casual prototyping
JPA object store
uses Hibernate as underlying implementation
requires @DiscriminatorValue and @Id
to consistently support @Any associations
SQL Object Store
Berkeley DB Object Store
v
15. Pluggable Viewers
DnD Viewer Eclipse RCP Viewer
HTML Viewer in development
Scimpi Viewer
Vaadin Viewer
Headless Viewer just started
FitNesse Others?
RESTful Viewer GWT?
JavaFX?
NetBeans RCP?
Flex?
v
17. A detail on how to customize
Claim/object-short.shtml
using the Scimpi viewer
v
18. Agile acceptance testing
using FitNesse
Write scenario tests, without writing
fixtures
Act in same way as Naked Objects viewers
v
19. RESTful Support
Exposes domain objects and properties
as RESTful resources
Object Property Collection Action
GET current state n/a current n/a
of all contents
properties
PUT create set add item n/a
DELETE destroy clear remove item n/a
POST n/a n/a n/a invoke
Rendered as XHTML using CSS microlanguage
Write client-side code using JAX-RS annotations
JBoss RestEasy is underlying implementation`
v
21. Not an all or nothing affair
Committing to any new framework is risky
so don't!
Just use for prototyping and requirements elicitation
Minimal dependencies
Write a conventional front-end (eg Wicket)
Map to Hibernate or other JPA technology
Domain model are POJOs after all
Or, go the whole hog and deploy on Naked Objects
either rich client or web
use plugins for Scimpi, Rich Client Objects or DnD
write your own viewers?
Whichever, Naked Objects is a great way to get into
domain-driven design
v Page 21
22. Multiple Deployment Options
Embedded Custom Full
Pure Pojo MetaModel Presentation Deployment
• Use as a • Clothe with your • Clothe with • NOF provides all
development own UI your own UI the layers
tool
• NOF provides • NOF handles the • Deploy as a
• Deploy into any the app layer rest webapp
layered
enterprise • Use your own • Deploy as
architecture persistence client/server
layer
v
23. Deployment Options
Embedded Metamodel
bootstrap the metamodel
EmbeddedContext context = new MyEmbeddedContext();
NakedObjectsMetaModel nomm = public class Employee … {
new NakedObjectsMetaModel(
context, private String name;
ClaimRepositoryInMemory.class, @MemberOrder(sequence="1")
EmployeeRepositoryInMemory.class); @Disabled
nakedObjectsMetaModel.init(); public String getName() {
return name;
either reach into the metamodel }
public void setName(String lastName) {
NakedObjectSpecification employeeSpec = this.name = lastName;
nomm.getSpecificationLoader() }
.loadSpecification(Employee.class); …
}
NakedObjectAssociation nameAssoc =
employeeSpec.getAssociation("name");
DisabledFacet disabledFacet =
nameAssoc.getFacet(DisabledFacet.class);
System.out.println("Disabled: " + disabledFacet);
or interact using headless viewer
HeadlessViewer viewer = nomm.getViewer();
Employee employee = new Employee();
Employee employeeView =
viewer.view(employee);
employeeView.setName("Joe");
v
24. Domain Driven Design
Ubiquitous Language
With a conscious effort by the team, the
domain model can provide the backbone
for that common language
Eric Evans
v Page 24
25. Domain Driven Design
Ubiquitous Language
Under Naked Objects, there is nothing to
talk about (or with) other than the
domain model ...
so the effort isn't particularly conscious
v Page 25
26. Before I forget...
Part 1 – Tools
DDD core concepts
Part 2 – Techniques
Patterns, idioms,
decoupling
Part 3 – Practices
FitNesse, Wicket,
JPA/Hibernate, RESTful &
ESBs
www.pragprog.com/titles/dhnako 25% discount code:
zDanHaywoodFeb2010
v Page 26
27. and don't you forget...
The DDD Exchange
11 June 2010
Please fill in your evaluations
free entrance for one lucky person!
v Page 27
28. Further Information
Perfection is finally achieved not
when there's no longer anything
to add, but when there's no
longer anything to take away …
when a body has been stripped
down to its nakedness
Antoine de Saint-Exupéry
Contact & Resources
dan@haywood-associates.co.uk
www.danhaywood.com
www.pragprog.com/titles/dhnako
www.nakedobjects.org
starobjects.sourceforge.net
v Page 28