Into the Domain
Mayank Bairagi
Software Consultant
Knoldus Software
Agenda (Part 1)
➢
Domain Driven Design : An Overview
➢
Domain
➢
Model
➢
Bounded Context
➢
Context Map
➢
Relationship Patterns
➢
Domain Objects
➢
Aggregates
➢
Repository
➢
Domain event
➢
CQRS
Agenda (Part 2)
➢
Domain Specific Language
➢
DSL : Introduction
➢
Anatomy
➢
Composing DSL
➢
Why Scala for DSL
➢
DSL Design in Scala
➢
Best Practice
WHAT IS DOMAIN ?
Domain is a sphere of knowledge, influence and activity
- wikipedia
WHAT IS DOMAIN ?
Domain is a sphere of knowledge, influence and activity
- wikipedia
Domain Driven Design is a methodology for evolving software that closely matches
our business requirement.
WHAT IS DOMAIN ?
Domain is a sphere of knowledge, influence and activity
- wikipedia
Domain Driven Design is a methodology for evolving software that closely matches our
business requirement.
Domain-driven design (DDD) is an approach to developing software for complex needs
by deeply connecting the implementation to an evolving model of the core business
concepts.
How to Identify core domain?
Ask questions
How to Identify core domain?
Ask questions like
➢ What keeps you awake at night
How to Identify core domain?
Ask questions like
➢ What keeps you awake at night.
➢ What makes your system worth writing.
How to Identify core domain?
Ask questions like
➢ What keeps you awake at night.
➢ What makes your system worth writing.
➢ Why not buy it off the self.
How to Identify core domain?
Ask questions like
➢ What keeps you awake at night.
➢ What makes your system worth writing.
➢ Why not buy it off the self.
➢ Why not outsource it.
How to Identify core domain?
Ask questions like
➢ What keeps you awake at night.
➢ What makes your system worth writing.
➢ Why not buy it off the self.
➢ Why not outsource it.
What is Model ?
What is Model ?
Don't think of the model as code.
What is Model ?
Don't think of the model as code.
Models are abstract set of tools used to solve domain problem.
What is Model ?
Don't think of the model as code.
Models are abstract set of tools used to solve problem within a domain.
Don't try to model reality.
Models to solve problem related to temperature
This is not our world
Everything simple is false
Everything which is complex is unusable
- Paul Valery
Ubiquitous Language
In order to search freelancer or project, we will consider inflectional and thesaurus feature of
elasticsearch to make the search more relevant. Additionally we will also exclude the stop words
from the search to make it more accurate.
Ubiquitous Language
In order to search freelancer or project, we will consider inflectional and thesaurus feature of
elasticsearch to make the search more relevant. Additionally we will also exclude the stop words
from the search to make it more accurate.
Ubiquitous Language
In the search functionality we will consider all the synonyms of the search phrase so that it does not
exclude relevant results. Moreover we will not differentiate any search word by its number (singular
or plural), tense, participle etc so that the result becomes more accurate. Additionally as expected in
any search, we will ignore all the noise words that do not have any value in the search. Such noise
words could be “am”, “but”, “where”, “about” etc.
Model(s) may represent
➢ your core domain.
Model(s) may represent
➢
your core domain.
➢
➢
a supporting domain
Model(s) may represent
➢
your core domain.
➢
a supporting domain
➢
a generic subdomain.
Model(s) may represent
➢
your core domain. Focus
➢
a supporting domain Consider outsource
➢
a generic subdomain. Consider off the shelf
Leasing Domain
➢
Identity
➢
Freelancer
➢
Customer
➢
Project
Bounded Context
A domain can have multiple model , each model can be represented by its bounded context.
Delineate applicability of particular module.
Explore model in isolation.
Own code and persistence mechanism.
Context Map
Draw a context map of all the bounded context.
Map what actually exists , not what you wish exsited.
Domain Object
Entity
➢ Must have an identity
➢ Must have a life cycle
➢ Most likely Mutable
➢ May be composed of other entities and value objects.
Value object
➢ No Identity
➢ Defined by its encapsulated attributes
➢ Treat value objects as immutable.
➢ Delegate business logic to value object.
Aggregates
➢
Group of related entities and value objects
➢
Useful when defining transaction, distribution and persistence.
➢
If two things need to be consistent together
Aggregate together
➢
Else
They belongs to separate aggregates.
➢
Within a bounded context there may have multiple aggregates.
Aggregate root
➢
Designate one entity as aggregate root.
➢
Allow external reference to only the aggregate root.
➢
Persist aggregate root along with its object graph.
Services
A place for operations that aren't naturally part of a domain object.
Services should be treated as immutable.
Operations on services are stateless.
What is Domain Event ?
What is Domain Event ?
Something important that happens within the domain that may lead to a stat change is
domain object.
What is Domain Event ?
Something important that happens within the domain that may lead to a stat change is
domain object.
A domain event can lead to another domain event.
eg. 6 balls can trigger an over.
What is Domain Event ?
Something important that happens within the domain that may lead to a stat change is
domain object.
A domain event can lead to another domain event.
eg. 6 balls can trigger an over.
Domain events are immutable.
What is Domain Event ?
Something important that happens within the domain that may lead to a stat change is
domain object.
A domain event can lead to another domain event.
eg. 6 balls can trigger an over.
Domain events are immutable.
Event Log
Domain event should be logged into event log.
Current state can be computed by reading the event log.
If necessary for performance , current state can be cached.
Can also serve as an audit log.
Command Query Responsibility Segregation
(CQRS)
Separate Read/Write model.
Define one model for writing data (command)
Define another model for reading data (query)
Both model operate on same aggregate.
References
➢
Domain Driven Design : Tackling complexity in the heart of software (By Eric Evans).
➢
http://martinfowler.com/tags/domain%20driven%20design.html
➢
http://dddcommunity.org/
➢
https://www.youtube.com/watch?v=RNUn2R7TptM
➢
http://www.slideshare.net/thinkddd
Thank you

Into the domain

  • 1.
    Into the Domain MayankBairagi Software Consultant Knoldus Software
  • 2.
    Agenda (Part 1) ➢ DomainDriven Design : An Overview ➢ Domain ➢ Model ➢ Bounded Context ➢ Context Map ➢ Relationship Patterns ➢ Domain Objects ➢ Aggregates ➢ Repository ➢ Domain event ➢ CQRS
  • 3.
    Agenda (Part 2) ➢ DomainSpecific Language ➢ DSL : Introduction ➢ Anatomy ➢ Composing DSL ➢ Why Scala for DSL ➢ DSL Design in Scala ➢ Best Practice
  • 4.
    WHAT IS DOMAIN? Domain is a sphere of knowledge, influence and activity - wikipedia
  • 5.
    WHAT IS DOMAIN? Domain is a sphere of knowledge, influence and activity - wikipedia Domain Driven Design is a methodology for evolving software that closely matches our business requirement.
  • 6.
    WHAT IS DOMAIN? Domain is a sphere of knowledge, influence and activity - wikipedia Domain Driven Design is a methodology for evolving software that closely matches our business requirement. Domain-driven design (DDD) is an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts.
  • 7.
    How to Identifycore domain? Ask questions
  • 8.
    How to Identifycore domain? Ask questions like ➢ What keeps you awake at night
  • 9.
    How to Identifycore domain? Ask questions like ➢ What keeps you awake at night. ➢ What makes your system worth writing.
  • 10.
    How to Identifycore domain? Ask questions like ➢ What keeps you awake at night. ➢ What makes your system worth writing. ➢ Why not buy it off the self.
  • 11.
    How to Identifycore domain? Ask questions like ➢ What keeps you awake at night. ➢ What makes your system worth writing. ➢ Why not buy it off the self. ➢ Why not outsource it.
  • 12.
    How to Identifycore domain? Ask questions like ➢ What keeps you awake at night. ➢ What makes your system worth writing. ➢ Why not buy it off the self. ➢ Why not outsource it.
  • 13.
  • 14.
    What is Model? Don't think of the model as code.
  • 15.
    What is Model? Don't think of the model as code. Models are abstract set of tools used to solve domain problem.
  • 16.
    What is Model? Don't think of the model as code. Models are abstract set of tools used to solve problem within a domain. Don't try to model reality.
  • 17.
    Models to solveproblem related to temperature
  • 18.
    This is notour world
  • 19.
    Everything simple isfalse Everything which is complex is unusable - Paul Valery
  • 20.
    Ubiquitous Language In orderto search freelancer or project, we will consider inflectional and thesaurus feature of elasticsearch to make the search more relevant. Additionally we will also exclude the stop words from the search to make it more accurate.
  • 21.
    Ubiquitous Language In orderto search freelancer or project, we will consider inflectional and thesaurus feature of elasticsearch to make the search more relevant. Additionally we will also exclude the stop words from the search to make it more accurate.
  • 22.
    Ubiquitous Language In thesearch functionality we will consider all the synonyms of the search phrase so that it does not exclude relevant results. Moreover we will not differentiate any search word by its number (singular or plural), tense, participle etc so that the result becomes more accurate. Additionally as expected in any search, we will ignore all the noise words that do not have any value in the search. Such noise words could be “am”, “but”, “where”, “about” etc.
  • 23.
    Model(s) may represent ➢your core domain.
  • 24.
    Model(s) may represent ➢ yourcore domain. ➢ ➢ a supporting domain
  • 25.
    Model(s) may represent ➢ yourcore domain. ➢ a supporting domain ➢ a generic subdomain.
  • 26.
    Model(s) may represent ➢ yourcore domain. Focus ➢ a supporting domain Consider outsource ➢ a generic subdomain. Consider off the shelf
  • 27.
  • 28.
    Bounded Context A domaincan have multiple model , each model can be represented by its bounded context. Delineate applicability of particular module. Explore model in isolation. Own code and persistence mechanism.
  • 31.
    Context Map Draw acontext map of all the bounded context. Map what actually exists , not what you wish exsited.
  • 32.
    Domain Object Entity ➢ Musthave an identity ➢ Must have a life cycle ➢ Most likely Mutable ➢ May be composed of other entities and value objects. Value object ➢ No Identity ➢ Defined by its encapsulated attributes ➢ Treat value objects as immutable. ➢ Delegate business logic to value object.
  • 33.
    Aggregates ➢ Group of relatedentities and value objects ➢ Useful when defining transaction, distribution and persistence. ➢ If two things need to be consistent together Aggregate together ➢ Else They belongs to separate aggregates. ➢ Within a bounded context there may have multiple aggregates.
  • 34.
    Aggregate root ➢ Designate oneentity as aggregate root. ➢ Allow external reference to only the aggregate root. ➢ Persist aggregate root along with its object graph.
  • 38.
    Services A place foroperations that aren't naturally part of a domain object. Services should be treated as immutable. Operations on services are stateless.
  • 39.
  • 40.
    What is DomainEvent ? Something important that happens within the domain that may lead to a stat change is domain object.
  • 41.
    What is DomainEvent ? Something important that happens within the domain that may lead to a stat change is domain object. A domain event can lead to another domain event. eg. 6 balls can trigger an over.
  • 42.
    What is DomainEvent ? Something important that happens within the domain that may lead to a stat change is domain object. A domain event can lead to another domain event. eg. 6 balls can trigger an over. Domain events are immutable.
  • 43.
    What is DomainEvent ? Something important that happens within the domain that may lead to a stat change is domain object. A domain event can lead to another domain event. eg. 6 balls can trigger an over. Domain events are immutable.
  • 44.
    Event Log Domain eventshould be logged into event log. Current state can be computed by reading the event log. If necessary for performance , current state can be cached. Can also serve as an audit log.
  • 45.
    Command Query ResponsibilitySegregation (CQRS) Separate Read/Write model. Define one model for writing data (command) Define another model for reading data (query) Both model operate on same aggregate.
  • 48.
    References ➢ Domain Driven Design: Tackling complexity in the heart of software (By Eric Evans). ➢ http://martinfowler.com/tags/domain%20driven%20design.html ➢ http://dddcommunity.org/ ➢ https://www.youtube.com/watch?v=RNUn2R7TptM ➢ http://www.slideshare.net/thinkddd
  • 49.