SlideShare a Scribd company logo
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

Structure in c
Structure in cStructure in c
Structure in c
Samsil Arefin
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
Padma Kannan
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
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
 
SEMINAR
SEMINARSEMINAR
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
Vimukthi 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 Unions
Dhrumil 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 Deconstructed
Paul Sterk
 
Java8 and Functional Programming
Java8 and Functional ProgrammingJava8 and Functional Programming
Java8 and Functional Programming
Yiguang Hu
 
Type casting
Type castingType casting
Type casting
simarsimmygrewal
 
Data Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersData Structure Interview Questions & Answers
Data Structure Interview Questions & Answers
Satyam 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.pptx
BilalHussainShah5
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
Codemotion
 
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
sadhana312471
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin 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 2017
Codemotion
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
John Stevenson
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfak
Asfak Mahamud
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
Ted Leung
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojure
John Stevenson
 
Get into Functional Programming with Clojure
Get into Functional Programming with ClojureGet into Functional Programming with Clojure
Get into Functional Programming with Clojure
John 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 Programming
Aapo Kyrölä
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
Robbin 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 processor
Tatu Saloranta
 
Modern C++
Modern C++Modern C++
Modern C++
Richard Thomson
 
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
Katie Gulley
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
SreeVani74
 

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 ... Functions
Michal Bigos
 
Scala eXchange 2013 Report
Scala eXchange 2013 ReportScala eXchange 2013 Report
Scala eXchange 2013 Report
Michal Bigos
 
SBT Crash Course
SBT Crash CourseSBT Crash Course
SBT Crash Course
Michal Bigos
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
Michal 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 arise
Michal Bigos
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
Michal 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

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

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