Copyright © 2015 SolutionsIQ Inc. All rights reserved.
6801 185th Ave NE, Suite 200
Redmond, WA 98052
solutionsiq.com
1.800.235.4091
The craft of business driven design
Agenda
• We will learn one strategic design pattern in Domain driven design
• This is the most important and fundamental pattern in Domain driven design
XPIndia2016 3
All problems , functions and objects depicted in this workshop are
entirely fictitious. Any similarity to actual problems , classes or
functions living or dead, is purely coincidental.
XPIndia2016 4
XPIndia2016 5
e Slide
XPIndia2016 6
Operator
Name
Id
Login()
Customer
Name
Phone
ID
Booking system
book(Customer)
List <Trip>
Cab Tracker
getCabs(Count , SrcID )
Route getRoute(SrcID , DesID )
Cab
Driver Name
Phone No
ID
Trip
LocID SrcID
LocID DesID
Cab
Customer
route
administration
AddCab( cab)
Add Customer ()
ActivateCab()
DeActivateCab()
Reports
sendSMS()
Route
List <LocID>
ID Customer name p
h
ID Driver name p
h
» Legacy system design XPIndia2016 7
*
 As a customer of SheTaxi , I want to book the nearest SheTaxi
based on my GPS location so that I reach my destination ASAP.
 As a car owner, I want to attach myself to SheTaxi so that I get
more customers
 As a customer of SheTaxi , I want to view the rate card so that I
can estimate the fare .
XPIndia2016 8
» A
 As a customer of SheTaxi , I want to view available cabs based on
a given gps location so that I get approximate time I need to wait
after booking .
 As a customer of SheTaxi , I want to view the approximate fare of
my journey so that I can estimate the fare .
 As the management of SheTaxi , I want customers to rate the
driver in a scale of 1 to 5 , 1 being worst and 5 being best , so we
can get feedback and improve our services .
» B
XPIndia2016 9
As the management of SheTaxi, we want to track the exact route
using GPS coordinates , time taken and distance travelled so that
SheTaxi can generate invoices to customers .
As a SheTaxi cabdriver , I want to get a route map (GPS coordinates )
based on my customers destination and pickup point so that I can
complete my trip ASAP.
As the management of SheTaxi , we want an exclusive feature for
our VIP customers, an option to book cab drivers with rating 4+ so
that we can retain our VIP customers.
» C
XPIndia2016 10
As a customer of SheTaxi , I want my invoice be emailed so that I
need not ask for a written invoice.
As the management of SheTaxi , I want to access previous trip data
for each drivers so that we can make weekly payments to them
As the management of SheTaxi , we want an exclusive feature for
our VIP customers, an option to integrate their invoices to ”
www.expensify.com”
» D
XPIndia2016 11
Example : Super Market
I 'am using a simple example to explain the problem , same is applicable for bigger complex systems
The super market has many products to sell
Each product has a
 quality
 cost
The rules for computation of Quality and Cost are different for
each product
Abstract Product
computeQuality()
computeCost ()
Concreate product 1
Concreate product 2
Concreate product n-1
Concreate product N
Example of a
concreate product
XPIndia2016 12
Is this the best design ?
Onion
computeQuality()
computeCost ()
»Is this following SRP ? Single responsibility principle
»SRP : A class should have only one reason to change
»What if the pricing strategy of a product varies
from time to time ?
XPIndia2016 13
How about a different design
Abstract Product
Pricing strategy
computeQuality()
Concreate product 1
Concreate product 2
Concreate product n-1
Concreate product N
PricingStrategy
CompteCost()
Strategy 1
Strategy 2
Strategy 3
XPIndia2016 14
Another design
Product
PricingStrategy
QualityRule
PricingStrategy
CompteCost()
Strategy 1
Strategy 2
Strategy 3
QualityRule
Quality()
Rule 1
Rule 2
XPIndia2016 15
Which design is better ?
XPIndia2016 16
Which design is better ?
Answer is : it depends
Dependents on what ?
Lest try to define this context
Context
XPIndia2016 17
Which design is better ?
If mostly we will be only adding / removing products
XPIndia2016 18
Which design is better ?
• We will be constantly adding new products , also
• We need to modify pricing strategy every now and then
for existing products
XPIndia2016 19
Which design is better ?
• We need to often modify both pricing strategy & quality
rule for existing products
XPIndia2016 20
There is nothing like a good or bad design
we can only evaluate a design once we associate it with
a context
The context is the actual business problem we need to
solve
XPIndia2016 21
Coordinate geometry package Graphics rendering package
Core library
Team BTeam A
XPIndia2016 22
Coordinate geometry package Graphics rendering package
Team A Team B
float x , float y , float length, float
breath
Line getDiagonal()
Float getDistanceFromPoint(Point)
Void transform(Matrix)
Float getSurfaceArea…………
float x , float y , float length, float
breath
Image Texture;
Line get Diagonal ()
Matrix Convert (matrix)
Float getDistanceFromPoint(Point)
Void transform(Matrix)
Float getSurfaceArea
Void Scale (int x)
Void deform (matrix)
float x , float y , float length, float
breath , int height , int width
Image Texture;
Line get Diagonal()
Matrix Convert (matrix)
Float getDistanceFromPoint(Point)
Void transform(Matrix)
Float getSurfaceArea
Void Scale (int x)
Void deform (matrix)
»The dirty evolution of rectangle class
XPIndia2016 23
Coordinate geometry package Graphics rendering package
Core library
Team BTeam A
XPIndia2016 24
If design reuse is done incorrectly it could slowly ,
unknowingly contaminate the entire system
XPIndia2016 25
XPIndia2016 26
Which design decision is better to store cab locations in real time ?
XPIndia2016 27
» Accuracy ++
» Complexity++
» Retrieval performance –-
» Shortest route++
» Accuracy --
» Simplicity ++
» Retrieval performance++
» Shortest route --
• Design reuse is always good
• Software design should always strive towards perfection
XPIndia2016 28
Myths
Domain , sub domain and Bounded Context
XPIndia2016 29
Context Map
XPIndia2016 30
Bounded Context is an explicit boundary within which a
domain model exists
XPIndia2016 31
• Design reuse is always good within its bounded context
• Software design should always strive towards perfection with
in its bounded context
XPIndia2016 32
Let apply what we learned and redesign
XPIndia2016 33
XPIndia2016 34
Present your design
Domain Driven Design what we didn’t cover
XPIndia2016 35
• Entity
• Value Object
• Aggregate
• Domain Event
• Service
• Repository
• Factory
» Ubiquitous language
If your bitten by the DDD bug you have two choices ,the blue pill or the red pill
XPIndia2016 36
Questions
XPIndia2016 37
Domain Driven Design what we didn’t cover
XPIndia2016 38

DDD_upload

  • 2.
    Copyright © 2015SolutionsIQ Inc. All rights reserved. 6801 185th Ave NE, Suite 200 Redmond, WA 98052 solutionsiq.com 1.800.235.4091 The craft of business driven design
  • 3.
    Agenda • We willlearn one strategic design pattern in Domain driven design • This is the most important and fundamental pattern in Domain driven design XPIndia2016 3
  • 4.
    All problems ,functions and objects depicted in this workshop are entirely fictitious. Any similarity to actual problems , classes or functions living or dead, is purely coincidental. XPIndia2016 4
  • 5.
  • 6.
  • 7.
    Operator Name Id Login() Customer Name Phone ID Booking system book(Customer) List <Trip> CabTracker getCabs(Count , SrcID ) Route getRoute(SrcID , DesID ) Cab Driver Name Phone No ID Trip LocID SrcID LocID DesID Cab Customer route administration AddCab( cab) Add Customer () ActivateCab() DeActivateCab() Reports sendSMS() Route List <LocID> ID Customer name p h ID Driver name p h » Legacy system design XPIndia2016 7 *
  • 8.
     As acustomer of SheTaxi , I want to book the nearest SheTaxi based on my GPS location so that I reach my destination ASAP.  As a car owner, I want to attach myself to SheTaxi so that I get more customers  As a customer of SheTaxi , I want to view the rate card so that I can estimate the fare . XPIndia2016 8 » A
  • 9.
     As acustomer of SheTaxi , I want to view available cabs based on a given gps location so that I get approximate time I need to wait after booking .  As a customer of SheTaxi , I want to view the approximate fare of my journey so that I can estimate the fare .  As the management of SheTaxi , I want customers to rate the driver in a scale of 1 to 5 , 1 being worst and 5 being best , so we can get feedback and improve our services . » B XPIndia2016 9
  • 10.
    As the managementof SheTaxi, we want to track the exact route using GPS coordinates , time taken and distance travelled so that SheTaxi can generate invoices to customers . As a SheTaxi cabdriver , I want to get a route map (GPS coordinates ) based on my customers destination and pickup point so that I can complete my trip ASAP. As the management of SheTaxi , we want an exclusive feature for our VIP customers, an option to book cab drivers with rating 4+ so that we can retain our VIP customers. » C XPIndia2016 10
  • 11.
    As a customerof SheTaxi , I want my invoice be emailed so that I need not ask for a written invoice. As the management of SheTaxi , I want to access previous trip data for each drivers so that we can make weekly payments to them As the management of SheTaxi , we want an exclusive feature for our VIP customers, an option to integrate their invoices to ” www.expensify.com” » D XPIndia2016 11
  • 12.
    Example : SuperMarket I 'am using a simple example to explain the problem , same is applicable for bigger complex systems The super market has many products to sell Each product has a  quality  cost The rules for computation of Quality and Cost are different for each product Abstract Product computeQuality() computeCost () Concreate product 1 Concreate product 2 Concreate product n-1 Concreate product N Example of a concreate product XPIndia2016 12
  • 13.
    Is this thebest design ? Onion computeQuality() computeCost () »Is this following SRP ? Single responsibility principle »SRP : A class should have only one reason to change »What if the pricing strategy of a product varies from time to time ? XPIndia2016 13
  • 14.
    How about adifferent design Abstract Product Pricing strategy computeQuality() Concreate product 1 Concreate product 2 Concreate product n-1 Concreate product N PricingStrategy CompteCost() Strategy 1 Strategy 2 Strategy 3 XPIndia2016 14
  • 15.
  • 16.
    Which design isbetter ? XPIndia2016 16
  • 17.
    Which design isbetter ? Answer is : it depends Dependents on what ? Lest try to define this context Context XPIndia2016 17
  • 18.
    Which design isbetter ? If mostly we will be only adding / removing products XPIndia2016 18
  • 19.
    Which design isbetter ? • We will be constantly adding new products , also • We need to modify pricing strategy every now and then for existing products XPIndia2016 19
  • 20.
    Which design isbetter ? • We need to often modify both pricing strategy & quality rule for existing products XPIndia2016 20
  • 21.
    There is nothinglike a good or bad design we can only evaluate a design once we associate it with a context The context is the actual business problem we need to solve XPIndia2016 21
  • 22.
    Coordinate geometry packageGraphics rendering package Core library Team BTeam A XPIndia2016 22
  • 23.
    Coordinate geometry packageGraphics rendering package Team A Team B float x , float y , float length, float breath Line getDiagonal() Float getDistanceFromPoint(Point) Void transform(Matrix) Float getSurfaceArea………… float x , float y , float length, float breath Image Texture; Line get Diagonal () Matrix Convert (matrix) Float getDistanceFromPoint(Point) Void transform(Matrix) Float getSurfaceArea Void Scale (int x) Void deform (matrix) float x , float y , float length, float breath , int height , int width Image Texture; Line get Diagonal() Matrix Convert (matrix) Float getDistanceFromPoint(Point) Void transform(Matrix) Float getSurfaceArea Void Scale (int x) Void deform (matrix) »The dirty evolution of rectangle class XPIndia2016 23
  • 24.
    Coordinate geometry packageGraphics rendering package Core library Team BTeam A XPIndia2016 24
  • 25.
    If design reuseis done incorrectly it could slowly , unknowingly contaminate the entire system XPIndia2016 25
  • 26.
  • 27.
    Which design decisionis better to store cab locations in real time ? XPIndia2016 27 » Accuracy ++ » Complexity++ » Retrieval performance –- » Shortest route++ » Accuracy -- » Simplicity ++ » Retrieval performance++ » Shortest route --
  • 28.
    • Design reuseis always good • Software design should always strive towards perfection XPIndia2016 28 Myths
  • 29.
    Domain , subdomain and Bounded Context XPIndia2016 29
  • 30.
  • 31.
    Bounded Context isan explicit boundary within which a domain model exists XPIndia2016 31
  • 32.
    • Design reuseis always good within its bounded context • Software design should always strive towards perfection with in its bounded context XPIndia2016 32
  • 33.
    Let apply whatwe learned and redesign XPIndia2016 33
  • 34.
  • 35.
    Domain Driven Designwhat we didn’t cover XPIndia2016 35 • Entity • Value Object • Aggregate • Domain Event • Service • Repository • Factory » Ubiquitous language
  • 36.
    If your bittenby the DDD bug you have two choices ,the blue pill or the red pill XPIndia2016 36
  • 37.
  • 38.
    Domain Driven Designwhat we didn’t cover XPIndia2016 38