WHERE DO I HAVE TO PUT MY BUSINESS LOGIC?
GRAILS IS NOT MY DOMAIN MODEL.
Greach 2014, Madrid, Spain
Presented March, 28th, 2014
What’s business logic exactly? What’s a domain model? How does the use of a framework like Grails
influence how we build a domain model? How can the use of patterns helps us in building our system?
This talk will approach the problems that we have to face when we put a tool in the core of our
system and we will discuss whether the price we pay for using the Grails framework is too high.
A lot of resources at the end!!
32. Functional Programming
- Inmutability
- Transaction scripts
- Stateless services
- Stateless API
- Rare workflows …
- Objects with state… but we don’t usually use them
“Why OO in web, when usually is
DB -> Object -> Process -> Object -> DB”
Functional Programming for the Object-Oriented
Programmer
Brian Marick
37. Ubiquitous Language
“A language structured around the domain
model and used by all team members to
connect all the activities of the team with the
software”
44. Entities
“When an object is distinguished by its identity,
rather than its attributes, make this primary to
its definition in the model”
45. Value Objects
“When you care only about the attributes of
an element of the model, classify it as a
VALUE OBJECT.
Don’t give it any identity…”
46. Services
“When a significant process or transformation
in the domain is not a natural responsibility of
an ENTITY or VALUE OBJECT, add an
operation to the model as a standalone
interface declared as a SERVICE.
Make the SERVICE stateless.”
48. Aggregates
“Cluster the ENTITIES and VALUE OBJECTS
into AGGREGATES and define boundaries
around each.
Choose one ENTITY to be the root of each
AGGREGATE, and control all access to the
objects inside the boundary through the root.
Allow external objects to hold references to the
root only.”
49. Factories
“Shift the responsibility for creating
instances of complex objects and
AGGREGATES to a separate object, which
may itself have no responsibility in the domain
model but is still part of the domain design.”
50. Repositories
“For each type of object that needs global
access, create an object that can provide the
illusion of an in-memory collection of all
objects of that type.”
52. Implementing Entities
These are Domain Classes in Grails. They come with
persistence already resolved through GORM.
hasOne vs. belongsTo property can be used to
define the lifecycle of entities and their relationships.
53. Implementing Value Objects
In Grails, you can use “embedded” property in
GORM field to manage a value object.
And deal with them with POGO
or Command Objects
60. All together …
In a more complex Aggregation, create a service to
manage, this service acts as a Repository. Control
invariants.
To access a simple Entity use GORM.
In a Domain Model with hasOne and belongsTo can act as
an Aggregate Root, and use GORM directly.
And we reserve Factories to instantiate external providers,
like email service, S3 access, push mobile notifications,
and so on …
65. Resources
http://www.slideshare.net/DimkaG/domain-driven-design-and-model-driven-development
- ideas to implement the building blocks.
http://blog.refactoringin.net/2011/08/17/grails-as-a-ddd-platform/
- Unique reference directly with Grails
- Repository??? with GORM…
Brian Marick - Functional Programming for the Object-Oriented Programmer
https://leanpub.com/fp-oo
http://www.mabishu.com/blog/2012/12/14/object-calisthenics-write-better-object-oriented-code/
Object Calisthenics Write Better OO Code
Javier Acero - Mi dominio es mio y no lo comparto
http://vimeo.com/69157481
(Spanish)