SlideShare a Scribd company logo
1 of 31
Avoid Cluttered Domain Models with DCI and Groovy ,[object Object]
About this talk ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
My goal with this talk is to… … make your brain boil of inspiration!
About DCI ,[object Object],[object Object],[object Object],[object Object]
DDD works well for this…
But less well for this… … which is quite common in midsize- to large systems
Because you either end up with this…
… or this….
What if…. … use-case logic could be ATTACHED to domain objects when needed but still OWNED by the application modul?
Like this….
Compile-time…
Deploy-time…
Runtime view…. … of an interaction within the ProduceQuarterlyForecast use-case…
Runtime view…. … of an interaction within the SendSignedOrdersToSupplier use-case…
Taking a look at the role implementation…. public class Article { List<OrderItem>  ordered ; PriceList  pricelist ; public BigDecimal calcNextQuaterSales() { BigDecimal qSales = … ordered .findAll {OrderItem item ->  item.deliveryDate > Calendar.nextQuaterStart  && item.deliveryDate < Calendar.nextQuaterEnd}.each {OrderItem item -> qSales += item.amount  *  pricelist .meanPriceBetweenDates (Calendar.nextQuaterStart, Calendar.nextQuaterEnd) } return qSales } }
Techically, how can we do this? … as a Java developer… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What does Groovy has to offer DCI? Mechanisms in Groovy to add code to an existing class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy Mixin Simple Sample Context:  CalculateNetPriceContext Data:  a BigDecimal Interaction:  netPrice  on Role  PriceRole
The code – Define the Role (the mixin) class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
The code – Context assigns role to data class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
The code – method to execute interaction class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
The code – ask the context to conduct the interaction class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
Let ’ s revisit the BIG system….
Clean dependency graph!
All is good so far – but what about… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What did I use it for? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
When doesn’t DCI make sense? ,[object Object],[object Object],[object Object]
Did I teach you DCI? Not sure, really…but I’m convinced it is useful ,[object Object],[object Object],[object Object],[object Object],[object Object]
Possible strategies for adoption As-is ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2: Framework 1:  No framework 3: IDE tools ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Plain Java with Groovy mixins 1 + Groovy extension (e.g. annotation ) Or a DCI-capable Java framework 2 + ?
Thanks for listening! Questions? ?
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

Viewers also liked

Analysis of near field distribution variation using awas electromagnetic code...
Analysis of near field distribution variation using awas electromagnetic code...Analysis of near field distribution variation using awas electromagnetic code...
Analysis of near field distribution variation using awas electromagnetic code...csandit
 
2013 mobile health summit
2013 mobile health summit2013 mobile health summit
2013 mobile health summitJohan Eltes
 
The Web Framework Dream Team
The Web Framework Dream TeamThe Web Framework Dream Team
The Web Framework Dream TeamJohan Eltes
 
Invånar styrd åtkomst av patientdata
Invånar styrd åtkomst av patientdataInvånar styrd åtkomst av patientdata
Invånar styrd åtkomst av patientdataJohan Eltes
 
EGPS Year End News Letter
EGPS Year End News LetterEGPS Year End News Letter
EGPS Year End News Letteryapsmail
 
How Sweden improved patient self service with ehealth
How Sweden improved patient self service with ehealthHow Sweden improved patient self service with ehealth
How Sweden improved patient self service with ehealthJohan Eltes
 
Lifestyles Forests and Sustentability
Lifestyles Forests and SustentabilityLifestyles Forests and Sustentability
Lifestyles Forests and SustentabilityCarlos Loyola
 
2016 04-06 vitalis nordic reference architecture personal connected health
2016 04-06 vitalis nordic reference architecture personal connected health2016 04-06 vitalis nordic reference architecture personal connected health
2016 04-06 vitalis nordic reference architecture personal connected healthJohan Eltes
 
Reference Architecture
Reference ArchitectureReference Architecture
Reference ArchitectureJohan Eltes
 

Viewers also liked (12)

Analysis of near field distribution variation using awas electromagnetic code...
Analysis of near field distribution variation using awas electromagnetic code...Analysis of near field distribution variation using awas electromagnetic code...
Analysis of near field distribution variation using awas electromagnetic code...
 
Winter holidays
Winter holidaysWinter holidays
Winter holidays
 
Asynch Soa
Asynch SoaAsynch Soa
Asynch Soa
 
2013 mobile health summit
2013 mobile health summit2013 mobile health summit
2013 mobile health summit
 
The Web Framework Dream Team
The Web Framework Dream TeamThe Web Framework Dream Team
The Web Framework Dream Team
 
Invånar styrd åtkomst av patientdata
Invånar styrd åtkomst av patientdataInvånar styrd åtkomst av patientdata
Invånar styrd åtkomst av patientdata
 
EGPS Year End News Letter
EGPS Year End News LetterEGPS Year End News Letter
EGPS Year End News Letter
 
How Sweden improved patient self service with ehealth
How Sweden improved patient self service with ehealthHow Sweden improved patient self service with ehealth
How Sweden improved patient self service with ehealth
 
Lifestyles Forests and Sustentability
Lifestyles Forests and SustentabilityLifestyles Forests and Sustentability
Lifestyles Forests and Sustentability
 
051110 Lituania Pp2
051110 Lituania Pp2051110 Lituania Pp2
051110 Lituania Pp2
 
2016 04-06 vitalis nordic reference architecture personal connected health
2016 04-06 vitalis nordic reference architecture personal connected health2016 04-06 vitalis nordic reference architecture personal connected health
2016 04-06 vitalis nordic reference architecture personal connected health
 
Reference Architecture
Reference ArchitectureReference Architecture
Reference Architecture
 

Similar to DCI with groovy

GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Steven Smith
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven designTim Mahy
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsLilia Sfaxi
 
Decide for Dummies
Decide for DummiesDecide for Dummies
Decide for Dummiespruizclaudia
 
DECIDE for Dummies
DECIDE for Dummies DECIDE for Dummies
DECIDE for Dummies DECIDEH2020
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Design patters java_meetup_slideshare [compatibility mode]
Design patters java_meetup_slideshare [compatibility mode]Design patters java_meetup_slideshare [compatibility mode]
Design patters java_meetup_slideshare [compatibility mode]Dimitris Dranidis
 
No more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureMarco Parenzan
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
Austin,TX Meetup presentation tensorflow final oct 26 2017
Austin,TX Meetup presentation tensorflow final oct 26 2017Austin,TX Meetup presentation tensorflow final oct 26 2017
Austin,TX Meetup presentation tensorflow final oct 26 2017Clarisse Hedglin
 
How To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex InfrastructureHow To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex Infrastructuremichael.labriola
 
Decoding DevOps Advancing Your Coding Career.pdf
Decoding DevOps Advancing Your Coding Career.pdfDecoding DevOps Advancing Your Coding Career.pdf
Decoding DevOps Advancing Your Coding Career.pdfSquad Center
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185Mahmoud Samir Fayed
 

Similar to DCI with groovy (20)

GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven design
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Decide for Dummies
Decide for DummiesDecide for Dummies
Decide for Dummies
 
DECIDE for Dummies
DECIDE for Dummies DECIDE for Dummies
DECIDE for Dummies
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Design patters java_meetup_slideshare [compatibility mode]
Design patters java_meetup_slideshare [compatibility mode]Design patters java_meetup_slideshare [compatibility mode]
Design patters java_meetup_slideshare [compatibility mode]
 
No more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and Azure
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
Austin,TX Meetup presentation tensorflow final oct 26 2017
Austin,TX Meetup presentation tensorflow final oct 26 2017Austin,TX Meetup presentation tensorflow final oct 26 2017
Austin,TX Meetup presentation tensorflow final oct 26 2017
 
How To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex InfrastructureHow To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex Infrastructure
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Decoding DevOps Advancing Your Coding Career.pdf
Decoding DevOps Advancing Your Coding Career.pdfDecoding DevOps Advancing Your Coding Career.pdf
Decoding DevOps Advancing Your Coding Career.pdf
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185
 
What’s Up, EDoc?!
What’s Up,EDoc?!What’s Up,EDoc?!
What’s Up, EDoc?!
 

More from Johan Eltes

2018 04-25 vitalis refark telemedicin
2018 04-25 vitalis refark telemedicin2018 04-25 vitalis refark telemedicin
2018 04-25 vitalis refark telemedicinJohan Eltes
 
Sweden on fhir - status report
Sweden on fhir - status reportSweden on fhir - status report
Sweden on fhir - status reportJohan Eltes
 
The ehealth architecture of the Swedish public healthcare payers
The ehealth architecture of the Swedish public healthcare payersThe ehealth architecture of the Swedish public healthcare payers
The ehealth architecture of the Swedish public healthcare payersJohan Eltes
 
Presentation of a pre-study on a national ecosystem for a shared medication r...
Presentation of a pre-study on a national ecosystem for a shared medication r...Presentation of a pre-study on a national ecosystem for a shared medication r...
Presentation of a pre-study on a national ecosystem for a shared medication r...Johan Eltes
 
Nordic reference architecture personal connected health
Nordic reference architecture personal connected healthNordic reference architecture personal connected health
Nordic reference architecture personal connected healthJohan Eltes
 
Swedish Health Innovation Resources at Stanford Med-X
Swedish Health Innovation Resources at Stanford Med-XSwedish Health Innovation Resources at Stanford Med-X
Swedish Health Innovation Resources at Stanford Med-XJohan Eltes
 
2014 04-08 arkitektur för gemensam informationsförsörjning
2014 04-08 arkitektur för gemensam informationsförsörjning2014 04-08 arkitektur för gemensam informationsförsörjning
2014 04-08 arkitektur för gemensam informationsförsörjningJohan Eltes
 

More from Johan Eltes (10)

2018 04-25 vitalis refark telemedicin
2018 04-25 vitalis refark telemedicin2018 04-25 vitalis refark telemedicin
2018 04-25 vitalis refark telemedicin
 
Sweden on fhir - status report
Sweden on fhir - status reportSweden on fhir - status report
Sweden on fhir - status report
 
The ehealth architecture of the Swedish public healthcare payers
The ehealth architecture of the Swedish public healthcare payersThe ehealth architecture of the Swedish public healthcare payers
The ehealth architecture of the Swedish public healthcare payers
 
Presentation of a pre-study on a national ecosystem for a shared medication r...
Presentation of a pre-study on a national ecosystem for a shared medication r...Presentation of a pre-study on a national ecosystem for a shared medication r...
Presentation of a pre-study on a national ecosystem for a shared medication r...
 
Nordic reference architecture personal connected health
Nordic reference architecture personal connected healthNordic reference architecture personal connected health
Nordic reference architecture personal connected health
 
Swedish Health Innovation Resources at Stanford Med-X
Swedish Health Innovation Resources at Stanford Med-XSwedish Health Innovation Resources at Stanford Med-X
Swedish Health Innovation Resources at Stanford Med-X
 
2014 04-08 arkitektur för gemensam informationsförsörjning
2014 04-08 arkitektur för gemensam informationsförsörjning2014 04-08 arkitektur för gemensam informationsförsörjning
2014 04-08 arkitektur för gemensam informationsförsörjning
 
Sca
ScaSca
Sca
 
Mashups
MashupsMashups
Mashups
 
Java EE6 CDI
Java EE6 CDIJava EE6 CDI
Java EE6 CDI
 

DCI with groovy

  • 1.
  • 2.
  • 3. My goal with this talk is to… … make your brain boil of inspiration!
  • 4.
  • 5. DDD works well for this…
  • 6. But less well for this… … which is quite common in midsize- to large systems
  • 7. Because you either end up with this…
  • 9. What if…. … use-case logic could be ATTACHED to domain objects when needed but still OWNED by the application modul?
  • 13. Runtime view…. … of an interaction within the ProduceQuarterlyForecast use-case…
  • 14. Runtime view…. … of an interaction within the SendSignedOrdersToSupplier use-case…
  • 15. Taking a look at the role implementation…. public class Article { List<OrderItem> ordered ; PriceList pricelist ; public BigDecimal calcNextQuaterSales() { BigDecimal qSales = … ordered .findAll {OrderItem item -> item.deliveryDate > Calendar.nextQuaterStart && item.deliveryDate < Calendar.nextQuaterEnd}.each {OrderItem item -> qSales += item.amount * pricelist .meanPriceBetweenDates (Calendar.nextQuaterStart, Calendar.nextQuaterEnd) } return qSales } }
  • 16.
  • 17.
  • 18. Groovy Mixin Simple Sample Context: CalculateNetPriceContext Data: a BigDecimal Interaction: netPrice on Role PriceRole
  • 19. The code – Define the Role (the mixin) class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
  • 20. The code – Context assigns role to data class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
  • 21. The code – method to execute interaction class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
  • 22. The code – ask the context to conduct the interaction class PriceRole { BigDecimal getNetPrice() { return this * 0.8 } } class CalculateNetPriceContext { def priceRole CalculateNetPriceContext(BigDecimal amount) { amount.metaClass.mixin(PriceRole) priceRole = amount } BigDecimal executeContext() { return priceRole.netPrice } } println new CalculateNetPriceContext(100.00).executeContext()
  • 23. Let ’ s revisit the BIG system….
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. Thanks for listening! Questions? ?
  • 31.

Editor's Notes

  1. Domändriven design förknippas med programmeringsspråk, ramverk och kanske modellering för att kunna beskriva och realisera system – både data och logik – utgående från den information som hanteras. I praktiken handlar det för oss utvecklare om att få fram programkod som i form av klasser, metoder och kanske mappningar mot databaser representerar domänobjekten. Vi har blivit ganska bra på att bygga EN applikation / ett system i ETT team enligt denna modell. Vi har olika sätt att fördela logik mellan tjänster och domänobjekt. Så länge det är ett utvecklings/förvaltningsobjekt (gemensamt ansvar) för alla lager, behöver vi inte fundera så mycket på hur förändringar påverkar olika lager. Vi kan prioritera en domänmodell med mycket logik för att få en objektorienterad programmeringsmodell. Det är helt ok att domänklasserna förändras i varje release av produkten. I en rik domänmodell kan koden bli svår att förstå. Det är lätta att fragmenteringen gör att man tappar greppet om helheten/användningsfallet. Det en baksida av att prioritera återanvändning. Det gör också att det tar ganska lång tid för nya medlemmar i teamet att bli produktiva. Eftersom vårt system är ett “ stuprör ” samverkar det med andra system genom integration. Komplexiteten ökar gradvis när nya användningsfall tillkommer. Förr eller senare önskar vi att vi hade ett mer procedurellt angreppssätt
  2. DDD blir betydligt mer komplext när systemet blir större och behöver modulariseras. Domänklasserna får fler intressenter och det blir plötsligt vikltigt att domänmodellen releasas separat och att den hålls så stabil som möjligt. Vi behöver hitta sätt att partitionera domänmodellen. Vi får svårare att knyta logik till domänklasserna eftersom all kunskap om användningsfallen inte finns fullt ut hos alla i teamet som är beroende av domänmodellen. Det blir svårt med relase-hanteringen när två team med olika leveransplaner är inne och hackar i domänklasserna.
  3. Håller man fast vid att ha logik i domänklasserna (vad som tillkommer pga ett use-case och vad som “ tillhör domänobjektet och har återanvändningspotential ” är ju en glidande skala. Det kostar möten och det kostar samordning, vilket fördyrar och komplicerar