SlideShare ist ein Scribd-Unternehmen logo
1 von 65
Downloaden Sie, um offline zu lesen
Where do I put my
Business Logic?
Antonio de la Torre
@adelatorrefoss
March 28th 2014
Grails is not my Domain Model
Antonio de la Torre
@adelatorrefoss
Engineer & Agile Coach @ Kaleidos
Madrid, Spain
Me
A lot of questions
&
one Proposal
1st. step
All code inside Controller
Scaffolding helps
Common methods
MVC
&
Skinny Controller
Fat Model
2nd. step
Move to Domain Model
Extra large User
God Object
&
Services layer
3rd. step
Move to Services
And now XXL Services
Anemic Model
&
Transaction Script
Problems
Service with too much
responsibility
1.- in Creation
complex objects, constraints and invariants
2.- too much invocations
a lot of injected services, no separation
3.- how to save()?
addTo, hstore, GORM, mongo, ...
Persistence is a
Hardware problem
No OOP
We implement
behaviour in Agile
Where is our
Business Logic?
but …
here it is ...
How looks like our unit tests?
mocks & stored data
Actions
Actions
Single Responsibility Principle (SRP)
SOLID
Tell, don’t ask
“Object Calisthenics. 9 steps to better SW design” , Jeff
Bay
GRASP
… are all smells
OOP?
What about FP?
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
So better if we use
Agnostic Patterns
Domain Driven Design
by Eric Evans
DDD
“The goal of domain-
driven design is to create
better software by
focusing on a model of the
domain rather than the
technology”
Tackling complexity
DDD is a way of dealing with complexity.
Complex is easy. Simple is a lot harder.
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”
DDD leads to
Model Driven Design
Test your model
Behaviour centric
Layered Arquitecture
Diagram
Entities
“When an object is distinguished by its identity,
rather than its attributes, make this primary to
its definition in the model”
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…”
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.”
Modules
“Choose MODULES that tell the story of the
system and contain a cohesive set of
concepts.”
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.”
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.”
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.”
Implementing
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.
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
Implementing Services
With our Services in Grails
● Dependency Injection
● Transaction support
Implementing Modules
Grails plug-in mechanism.
Implementing Aggregates
Aggregates are implemented in the hasMany -
belongsTo relationship.
Can control the root access within a Service.
Implementing Factories
Implement Factories classes to create new
instances with an abstract interface…
It could be configurable with properties.
Implementing Repositories
Grails Service can be used to implement a
dedicated Repository object that simply
delegates its operation to Grails GORM.
All together
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 …
In code ...
Model your domain, create your business logic,
and separate it from your infrastructure.
Resources
Domain Driven Design
Eric Evans
http://www.slideshare.net/thinkddd/domain-driven-design-dddsydney-2011
- (Intro) Complex vs Simple
http://pragprog.com/articles/tell-dont-ask
- Tell, don't ask
http://juan-garcia-carmona.blogspot.com.es/2012/11/solid-y-grasp-buenas-practicas-hacia-el.html
- SOLID
- Spanish
http://www.martinfowler.com/bliki/AnemicDomainModel.html
- Anemic Model
Resources
http://www.slideshare.net/sergiopolo/introduccin-a-ddd
(Spanish)
- Building Blocks
http://www.slideshare.net/harshjegadeesan/domain-driven-design-presentation
STARRED
- Intro
- Building Blocks
http://www.slideshare.net/GlenWilson/domain-driven-design-pattern-summaries-presentation
- Extense document with Pattern Summaries
http://www.slideshare.net/ziobrando/taming-complex-domains-with-domain-driven-design-presentation
STARRED!!
- Building Blocks
- Large Scale DDD
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)

Weitere ähnliche Inhalte

Ähnlich wie Where i put my business logic - Greach 2014, Madrid, Spain

Ähnlich wie Where i put my business logic - Greach 2014, Madrid, Spain (20)

Evolving your api architecture with the strangler pattern
Evolving your api architecture with the strangler patternEvolving your api architecture with the strangler pattern
Evolving your api architecture with the strangler pattern
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with Rails
 
Introduction to Machine Learning - WeCloudData
Introduction to Machine Learning - WeCloudDataIntroduction to Machine Learning - WeCloudData
Introduction to Machine Learning - WeCloudData
 
Introduction to Machine Learning - WeCloudData
Introduction to Machine Learning - WeCloudDataIntroduction to Machine Learning - WeCloudData
Introduction to Machine Learning - WeCloudData
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
 
ExperiaSphere: Open-Source Management and Orchestration--Introduction
ExperiaSphere: Open-Source Management and Orchestration--IntroductionExperiaSphere: Open-Source Management and Orchestration--Introduction
ExperiaSphere: Open-Source Management and Orchestration--Introduction
 
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
How I ended up contributing to Magento core
How I ended up contributing to Magento coreHow I ended up contributing to Magento core
How I ended up contributing to Magento core
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Let's talk about... Microservices
Let's talk about... MicroservicesLet's talk about... Microservices
Let's talk about... Microservices
 
17612235.ppt
17612235.ppt17612235.ppt
17612235.ppt
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Marionette - TorontoJS
Marionette - TorontoJSMarionette - TorontoJS
Marionette - TorontoJS
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 
Designingapplswithnet
DesigningapplswithnetDesigningapplswithnet
Designingapplswithnet
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
Beyond rails new
Beyond rails newBeyond rails new
Beyond rails new
 

Mehr von Antonio de la Torre Fernández

20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
Antonio de la Torre Fernández
 
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo EmprendeTaller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
Antonio de la Torre Fernández
 
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
Antonio de la Torre Fernández
 
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestadesCAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
Antonio de la Torre Fernández
 

Mehr von Antonio de la Torre Fernández (16)

20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
 
ITSmf Astur18 La agilidad como motor de cambio en las organizaciones
ITSmf Astur18 La agilidad como motor de cambio en las organizacionesITSmf Astur18 La agilidad como motor de cambio en las organizaciones
ITSmf Astur18 La agilidad como motor de cambio en las organizaciones
 
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo EmprendeTaller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
 
Discusiones y decisiones: herramientas para la efectividad
Discusiones y decisiones: herramientas para la efectividadDiscusiones y decisiones: herramientas para la efectividad
Discusiones y decisiones: herramientas para la efectividad
 
CAS2016 Community of Need & Community of Solutions (December 1st 2016)
CAS2016 Community of Need & Community of Solutions (December 1st 2016)CAS2016 Community of Need & Community of Solutions (December 1st 2016)
CAS2016 Community of Need & Community of Solutions (December 1st 2016)
 
El viaje de Angular1 a Angular2
El viaje de Angular1 a Angular2El viaje de Angular1 a Angular2
El viaje de Angular1 a Angular2
 
UX Agilista - UXSpain 2015
UX Agilista - UXSpain 2015UX Agilista - UXSpain 2015
UX Agilista - UXSpain 2015
 
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
 
¿Se puede implementar una Cultura Ágil?
¿Se puede implementar una Cultura Ágil?¿Se puede implementar una Cultura Ágil?
¿Se puede implementar una Cultura Ágil?
 
ALE - Why it's worth going?
ALE - Why it's worth going?ALE - Why it's worth going?
ALE - Why it's worth going?
 
ALE14 - Involving UX and Design in Agile Development #sketchnoting
ALE14 - Involving UX and Design in Agile Development #sketchnotingALE14 - Involving UX and Design in Agile Development #sketchnoting
ALE14 - Involving UX and Design in Agile Development #sketchnoting
 
A User Story - some ideas
A User Story - some ideasA User Story - some ideas
A User Story - some ideas
 
Mejoras CAS 2011
Mejoras CAS 2011Mejoras CAS 2011
Mejoras CAS 2011
 
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestadesCAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
 
Arquitectura en Alfresco
Arquitectura en AlfrescoArquitectura en Alfresco
Arquitectura en Alfresco
 
Nuevos negocios y empleos basados en el Software y el Conocimiento Libre
Nuevos negocios y empleos basados en el Software y el Conocimiento LibreNuevos negocios y empleos basados en el Software y el Conocimiento Libre
Nuevos negocios y empleos basados en el Software y el Conocimiento Libre
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Where i put my business logic - Greach 2014, Madrid, Spain