SlideShare a Scribd company logo
1 of 19
Download to read offline
Functional
Domain
ModelingBy /MichalBigos @teliatko
Agenda
1. FunctionalProgrammingGems
2. Example
3. Perception of State
4. What's Next...
Functional Programming Gems
Pure Functions
Functions w/o side-effects
Theyare referentialytransparent
//Definitionoffunction
defsomeComputation(value:Long):Long=value+3
//Definitionasfunctionliteral
valanotherComputation:(Long)=>Long=(value:Long)=>value+3
Functional Programming Gems
Immutable Data
Dataw/o shared mutable state
Theycan be shared freely... no locks, no semafores etc.
//Definitionofcaseobjects
sealedtraitProgrammingLanguageKind
caseobjectStaticextendsProgrammingLanguageKind
caseobjectDynamicextendsProgrammingLanguageKind
//Definitionofcaseclass
caseclassProgrammingLanguage(
name:String,
kind:ProgrammingLanguageKind
)
Functional Programming Gems
Persistent Data Structures
Always preserves the previous version of itself when itis
modified
Effectivelyimmutable with no in-place mutation
//Supposewehavealist...
vall1=List(1,2,3)
//Thenweaddaitemtoit
vall2=4::l
assert(l1!=l2)//yieldstrue
Functional Programming Gems
Algebraic Data Types, take one
An algebraic datatype is akind of composite type, i.e. atype
formed bycombiningother types
Datatypes with some algebra, i.e. structure and operations
Unit type, Sumtypeand Product type
e.g. Lists can byformalydescribed as L = I + X * L
valemptyList=List()//Unittype
valsimpleList=1::emptyList//Sumtype
valproductList=2::emptyList//Producttype
Functional Programming Gems
Algebraic Data Types, take two
Domain entities are represented usingproduct types
caseclasses are bestfitin Scala
//Tupleissimplestproducttype
valprogrammingLanguage=(name,kind)
//Producttypeviacaseclass
caseclassProgrammingLanguage(
name:String,
kind:ProgrammingLanguageKind
)
Functional Programming Gems
Algebraic Data Types, take three
Domain values and enums are represented usingsumtypes
Inheritance and sealed traits/classes are bestfitin Scala
//Exampleofsum-type,OptionfromScalalibrary(codesimplified)
sealedabstractclassOption[+A]
finalcaseclassSome[+A](x:A)extendsOption[A]
caseobjectNoneextendsOption[Nothing]
//Sumtypeviacaseobjects
sealedtraitProgrammingLanguageKind
caseobjectStaticextendsProgrammingLanguageKind
caseobjectDynamicextendsProgrammingLanguageKind
Functional Programming Gems
Function Composition
Functions compose when theycause no side-effects
Side-effects do notcompose
scala>deffoo(something:String):String=s"foo($something)"
scala>defbar(something:String):String=s"bar($something)"
valcomposit=foo_composebar_
valreverseComposit=foo_andThenbar_
composit("anything")
>foo(bar(anything))
reverseComposit("anything")
>bar(foo(anything))
Functional Programming Gems
Combinators
Applyhigh-order functions
Glue for chainingfunctions
Pure functions as domain invariants and behavior
foundmap{foundLine=>partitions.success}
| |
Combinator High-orderfn
Monadicchaining,viafor-comprehensions
for{ |
_<-quantityInvariant(quantity)
_<-priceInvariant(price)
(found,rest)<-productAlreadyExists(productId)
}yield{/*dosomething*/}
Functional Programming Gems
Side Effects
FP languages encourage isolatingside-effects from pure
domain logic
Known side-effects (notinsignigicant)
1. DBaccess
2. Logging
3. IO operations
Example
result.foreach{case(order,event)=>
orderRepository.saveOrUpdate(order)
}
Functional Programming Gems
More to cover
Ad-hoc polymorphism viaTypeClasses
Type-Lenses functionalupdates in your domain model
Example
Perception of State
Domain state is effecivelymutable
Can retain previous states
Historyof whathappened
In-place mutation are wrongfor domain model
Theycombine state with time
What's next
Event Sourcing
Everystate-modification on domain yields event
Domain change is achieved byapplyingthe eventto the
aggregate
Eventstream, allthe events applied on domain
What's next
CQRS
Commands execute operations on domain model
Queries arbitraryviews of data
Independentscalability
What's next
Memory Image and STM
Application state in memory
Application of events to currentstate on domain
Enables transactions on memory
Interesting Links
1.
2.
3.
4.
5.
6.
7.
8.
PureFunction(Wikipedia)
Referenctial Transparency(Wikipedia)
Persistent Data Structure(Wikipedia)
Presistend Data Structures and Managed References
ADT, Product and SumTypes (Bob Harper, PFPL)
SimpleMadeEasy(RichHickey)
FunctionComposition(Wikipedia)
Building Apps w/ Functional DomainModels (Debasish
Ghosh)
Thanks for your attention

More Related Content

What's hot

Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oopsPadma Kannan
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languagetanmaymodi4
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...journalBEEI
 
Exploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper reviewExploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper reviewVimukthi Wickramasinghe
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++AkshtaSuryawanshi
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And UnionsDhrumil Patel
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Lecture 12
Lecture 12Lecture 12
Lecture 12Rana Ali
 
Neural Nets Deconstructed
Neural Nets DeconstructedNeural Nets Deconstructed
Neural Nets DeconstructedPaul Sterk
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional ProgrammingYiguang Hu
 
Data Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersData Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersSatyam Jaiswal
 

What's hot (20)

Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Structure in C
Structure in CStructure in C
Structure in C
 
Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...Search for a substring of characters using the theory of non-deterministic fi...
Search for a substring of characters using the theory of non-deterministic fi...
 
SEMINAR
SEMINARSEMINAR
SEMINAR
 
Exploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper reviewExploring Strategies for Training Deep Neural Networks paper review
Exploring Strategies for Training Deep Neural Networks paper review
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
Neural Nets Deconstructed
Neural Nets DeconstructedNeural Nets Deconstructed
Neural Nets Deconstructed
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
 
Type casting
Type castingType casting
Type casting
 
Data Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersData Structure Interview Questions & Answers
Data Structure Interview Questions & Answers
 

Similar to Functional Domain Modeling

Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptxBilalHussainShah5
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in ClojureCodemotion
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Codemotion
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with ClojureJohn Stevenson
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfakAsfak Mahamud
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojureJohn Stevenson
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with ClojureJohn Stevenson
 
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...Codemotion
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03Niit Care
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional ProgrammingAapo Kyrölä
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascriptRobbin Zhao
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTatu Saloranta
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core ModuleKatie Gulley
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfSreeVani74
 

Similar to Functional Domain Modeling (20)

Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017Thinking Functionally - John Stevenson - Codemotion Rome 2017
Thinking Functionally - John Stevenson - Codemotion Rome 2017
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfak
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojure
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
 
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processor
 
Modern C++
Modern C++Modern C++
Modern C++
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 

More from Michal Bigos

All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Scala eXchange 2013 Report
Scala eXchange 2013 ReportScala eXchange 2013 Report
Scala eXchange 2013 ReportMichal Bigos
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scalaMichal Bigos
 
Option, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they ariseOption, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they ariseMichal Bigos
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBMichal Bigos
 

More from Michal Bigos (6)

All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
Scala eXchange 2013 Report
Scala eXchange 2013 ReportScala eXchange 2013 Report
Scala eXchange 2013 Report
 
SBT Crash Course
SBT Crash CourseSBT Crash Course
SBT Crash Course
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 
Option, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they ariseOption, Either, Try and what to do with corner cases when they arise
Option, Either, Try and what to do with corner cases when they arise
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
 

Recently uploaded

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Functional Domain Modeling

  • 2. Agenda 1. FunctionalProgrammingGems 2. Example 3. Perception of State 4. What's Next...
  • 3. Functional Programming Gems Pure Functions Functions w/o side-effects Theyare referentialytransparent //Definitionoffunction defsomeComputation(value:Long):Long=value+3 //Definitionasfunctionliteral valanotherComputation:(Long)=>Long=(value:Long)=>value+3
  • 4. Functional Programming Gems Immutable Data Dataw/o shared mutable state Theycan be shared freely... no locks, no semafores etc. //Definitionofcaseobjects sealedtraitProgrammingLanguageKind caseobjectStaticextendsProgrammingLanguageKind caseobjectDynamicextendsProgrammingLanguageKind //Definitionofcaseclass caseclassProgrammingLanguage( name:String, kind:ProgrammingLanguageKind )
  • 5. Functional Programming Gems Persistent Data Structures Always preserves the previous version of itself when itis modified Effectivelyimmutable with no in-place mutation //Supposewehavealist... vall1=List(1,2,3) //Thenweaddaitemtoit vall2=4::l assert(l1!=l2)//yieldstrue
  • 6. Functional Programming Gems Algebraic Data Types, take one An algebraic datatype is akind of composite type, i.e. atype formed bycombiningother types Datatypes with some algebra, i.e. structure and operations Unit type, Sumtypeand Product type e.g. Lists can byformalydescribed as L = I + X * L valemptyList=List()//Unittype valsimpleList=1::emptyList//Sumtype valproductList=2::emptyList//Producttype
  • 7. Functional Programming Gems Algebraic Data Types, take two Domain entities are represented usingproduct types caseclasses are bestfitin Scala //Tupleissimplestproducttype valprogrammingLanguage=(name,kind) //Producttypeviacaseclass caseclassProgrammingLanguage( name:String, kind:ProgrammingLanguageKind )
  • 8. Functional Programming Gems Algebraic Data Types, take three Domain values and enums are represented usingsumtypes Inheritance and sealed traits/classes are bestfitin Scala //Exampleofsum-type,OptionfromScalalibrary(codesimplified) sealedabstractclassOption[+A] finalcaseclassSome[+A](x:A)extendsOption[A] caseobjectNoneextendsOption[Nothing] //Sumtypeviacaseobjects sealedtraitProgrammingLanguageKind caseobjectStaticextendsProgrammingLanguageKind caseobjectDynamicextendsProgrammingLanguageKind
  • 9. Functional Programming Gems Function Composition Functions compose when theycause no side-effects Side-effects do notcompose scala>deffoo(something:String):String=s"foo($something)" scala>defbar(something:String):String=s"bar($something)" valcomposit=foo_composebar_ valreverseComposit=foo_andThenbar_ composit("anything") >foo(bar(anything)) reverseComposit("anything") >bar(foo(anything))
  • 10. Functional Programming Gems Combinators Applyhigh-order functions Glue for chainingfunctions Pure functions as domain invariants and behavior foundmap{foundLine=>partitions.success} | | Combinator High-orderfn Monadicchaining,viafor-comprehensions for{ | _<-quantityInvariant(quantity) _<-priceInvariant(price) (found,rest)<-productAlreadyExists(productId) }yield{/*dosomething*/}
  • 11. Functional Programming Gems Side Effects FP languages encourage isolatingside-effects from pure domain logic Known side-effects (notinsignigicant) 1. DBaccess 2. Logging 3. IO operations Example result.foreach{case(order,event)=> orderRepository.saveOrUpdate(order) }
  • 12. Functional Programming Gems More to cover Ad-hoc polymorphism viaTypeClasses Type-Lenses functionalupdates in your domain model
  • 14. Perception of State Domain state is effecivelymutable Can retain previous states Historyof whathappened In-place mutation are wrongfor domain model Theycombine state with time
  • 15. What's next Event Sourcing Everystate-modification on domain yields event Domain change is achieved byapplyingthe eventto the aggregate Eventstream, allthe events applied on domain
  • 16. What's next CQRS Commands execute operations on domain model Queries arbitraryviews of data Independentscalability
  • 17. What's next Memory Image and STM Application state in memory Application of events to currentstate on domain Enables transactions on memory
  • 18. Interesting Links 1. 2. 3. 4. 5. 6. 7. 8. PureFunction(Wikipedia) Referenctial Transparency(Wikipedia) Persistent Data Structure(Wikipedia) Presistend Data Structures and Managed References ADT, Product and SumTypes (Bob Harper, PFPL) SimpleMadeEasy(RichHickey) FunctionComposition(Wikipedia) Building Apps w/ Functional DomainModels (Debasish Ghosh)
  • 19. Thanks for your attention