Upgrade to Pro — share decks privately, control downloads, hide ads and more …

practice-DDD-with-Scala_en

 practice-DDD-with-Scala_en

The Practice DDD with Scala at Scala Matsuri 2018.
(日本語版 -> https://speakerdeck.com/crossroad0201/scala-on-ddd)

See sample code on GitHub. (Descriptions are Japanese only)
https://github.com/crossroad0201/ddd-on-scala

1. What's DDD?
2. DDD with Scala
3. Code Style
4. Architecture
- Layers
- Error Handling
5. Implement Components
- Application Service
- Entity
- Value Object
- Role
- Factory
- Repository
- Domain Service
- Domain Event, Publisher
- Query Model, Query Processor (CQRS)
- Event Subscriber
- Interface
6. Practice DDD

Yohei TSUJI

March 18, 2018
Tweet

More Decks by Yohei TSUJI

Other Decks in Programming

Transcript

  1. “ ” 2 - Osaka, Japan. - Java 17 years,

    Scala 2 years, and more… - Works as Software Architect, Developer for Enterprise system. - Currently, Developing a WEB Services using Scala and DDD on AWS. - I like Cars, Formula 1 and Climbing. Yohei TSUJI ” Twitter / GitHub / Qiita @crossroad0201 ΑΖ͓͘͠ئ͍͠·͢ɻ Freelance Programmer I am...
  2. This talk… 4 For such Engineers… - Practicing DDD, interested

    in Scala. - Using Scala, interested in DDD. - No experience with Scala and DDD. But want to use it if it's good. - Practicing DDD with Scala. Want to reference. 4DBMBͰ %%%Λ࣮ફ͍ͨ͠ΤϯδχΞͷํʹʂ
  3. Contents 5 6 4 3 2 5 1 What's DDD?

    DDD with Scala Code Style Architecture Implement Components Practice DDD ໨࣍
  4. In a nutshell… 7 Principles for developing software that's easy

    to change using Object-Oriented design. - Conversation using common "Ubiquitous language". - Split "Domain Context" by business concern. - Define the Components and their responsibilities. …etc มߋ͕༰қͳιϑτ΢ΣΞΛ࡞ΔͨΊͷݪଇूɻ
  5. and… 8 Writing the Domain knowledge in the program code

    using Domain language. υϝΠϯͷ஌ࣝΛɺυϝΠϯͷݴ༿Ͱɺίʔυʹॻ͘ɻ
  6. Components in DDD1 / 2 Aggregate Units that must be

    consistent in the domain. Factory Create a new Entity. Entity An object that need to be identified by unique ID in the Aggregate. Repository Persistence a Entity. Value Object An object that does not need to be identified in the Aggregate. Domain Service Applying the Business rule to the Domain model. 9 %%%Ͱఆٛ͞ΕΔίϯϙʔωϯτ ͦͷ̍ɻ
  7. CQRSCommand Query Responsibility Segregation Components in DDD2 / 2 Domain

    Event Business events occurring in the Aggregate. Event Subscriber Receive a Domain Event asynchronously, and update the Query Model. Event Publisher Publish a Domain Event to the Event queue. Query Processor Execute query to the Query Model. Query Model A read only view for the Domain model. Can contains multiple aggregates in the Query model. Application Service Implementing Use-Case using the Domain models. 10 %%%Ͱఆٛ͞ΕΔίϯϙʔωϯτ ͦͷ̎ɻ
  8. Anyway… 11 Domain-Driven DESIGN by Eric Evans Implementing Domain-Driven DESIGN

    by Vaughn Vernon But, It's necessary trial and error to practice DDD with functional programming language.... ؔ਺ܕݴޠͰͷ%%%ͷ࣮ફͰ͸ࢼߦࡨޡ͕ඞཁʜ
  9. Domain knowledge can be expressible naturally in program code. Why

    DDD with Scala? 15 / / ) / . / ( / ( - Can use SPACE between receiver object and method. - Can be omitted parentheses if only one parameter. - Can expand a code expression as the language specification. Code is the Domain specification. ίʔυ͕ࣗવจͷ࢓༷ॻʹͳΔɻ
  10. Object-Oriented with Functional programming. Why DDD with Scala? 16 Define

    Domain models statically. Define Domain behavior functionally. ) , ) ( , ( , ) , ( , ) , ) , ) , ( , ) , ( , ) , ) , ) , ΦϒδΣΫτࢦ޲ͱؔ਺ܕͷ͍͍ͱ͜ͲΓɻ
  11. Can define a type easily using case class. Why DDD

    with Scala? 17 ) ) ( ) ( ,) ) ,) - No Constructor. - No GETTER and SETTER. - Provide default implementation #equals(), #hashCode() and #toString(). - Easy immutable programming using #copy() method. Eliminate Boilerplate code from the Domain models. υϝΠϯϞσϧ͔ΒϘΠϥʔϓϨʔτΛഉআɻ
  12. Compatible with variables and functions. Why DDD with Scala? 18

    )/( = ( / =: (/ = . = = ( / Can change a property to derived-property easily. )/( = ( / : = . = = =( ) = ( / ϓϩύςΟͱಋग़ϓϩύςΟͷมߋ͕༰қɻ
  13. Can nest functions. Why DDD with Scala? 19 , ,(

    , : , ( , ) , , ,) = , , ) = , , , ( ) , , = Easy to name for steps of domain logic. - Clear usage scope. - Goodbye many cumbersome private methods. υϝΠϯϩδοΫʹࡉ໊͔͘લΛ෇͚΍͍͢ɻ
  14. Use immutable. 21 : . . ) . . )

    . . = ./ . .( . ) . . ) . . . : . ) . . ) . . = ./ . .( . ) . . ) . . - Do not use `var`, use `val`. In using case class, the properties are immutable. - Do not rewrite value, create an another instance that have new value. In using case class, easy to implement with #copy() method. Πϛϡʔλϒϧʹ࣮૷͢Δɻ
  15. Localize the side effects. 22 - All that do not

    return as return value are side effects. Such as persist data, throw an Exception …etc - All side effects can not be eliminated, but side effects can be localized. - In DDD, important to eliminate side effects from the core domain logic. ෭࡞༻ΛہॴԽ͢Δɻ
  16. 23 ( . ) ) ) ( = = )

    ( ) ) ( . ) ) ( ) ) ) / / .. ) = = ) ( ) ͍ͭͰʹӬଓԽ͠ͳ͍ɻ
  17. Use `for` expression. 24 ,<)- = = : ,< )-

    = ( - )- = = : ,< )- : ,< )- :( : ( - < :( : Name to a step by define nested function. Combine steps using `for` expression. GPS಺แࣜΛ࢖ͬͯɺॲཧεςοϓΛͭͳ͛Δɻ
  18. Use implicit parameters. 25 / =D .= . D .

    : =D .= D) .= D : = . .= D) .= D . D D " .= ( DD D =D.D) .= / =D : = " - Eliminate parameters that are not concerns of the domain (such as DB session) using implicit parameters. JNQMJDJUύϥϝλͰɺυϝΠϯϩδοΫ͔ΒϊΠζΛഉআɻ
  19. Do not use #copy() from outside. 26 - If abuse

    a #copy() method, You can not understand the intent of domain logic. - Use #copy() method only in self. )( ) ( (. (. (. (. (. ) (. (. " (. ( )( ) ( (. (. ") (. ( DPQZ ͸֎͔Βݺͼग़ͯ͠͸͍͚ͳ͍ɻ
  20. Do not omit variable names. 27 - < , -

    ( , ) , , , ) , , - , , , , , , , < ) , , < , < , , - < - ( , , ) , , - , , , < < , < Named by ubiquitous language. ม਺໊͸Ή΍Έʹུ͞ͳ͍ɻ Do not name like a formula.
  21. Prefixing to Optional variable. 28 - - : - /

    - - / - : - Prefixing the name of an option variable(such as `maybe`) makes it easier to read. - Scala has a type inference, so helpful if you can be resolved by name. 0QUJPOܕม਺ʹ͸ɺͦΕͱΘ͔Δ઀಄ࣙΛ෇͚Δɻ
  22. Use code formatter tools. 29 - < , < -

    ( , ) , , , ) , , - , , , , , , , < , , < , < , , - < , <<<<<<<<<<< - ( , ) , , , ) , , - , , , , , , , < , , < , < , , - Scalafmt, Scalareform …etc - Especially effective for `for` and `match-case` expressions. ࣗಈίʔυϑΥʔϚοτπʔϧͰಡΈ΍͘͢ɻ
  23. Layers and Responsibilities Modeling the Domain knowledge. Define Nouns as

    types, Verbs as functions. Persists a Domain models. Depends on middle wares, backend services. (such as RDBMS, MOM) Realize the Use-Case using a Domain models. provide interfaces for using application. (such as Web API, GUI and CLI) Infrastructure Layer Interface Layer Application Layer Domain Layer 32 ϨΠϠʔͱͦͷ੹຿ɻ
  24. Layers structure 33 Interface Application Domain Infrastructure The Layered Architecture

    Domain is depends on a Infrastructure. - Domain models do side effects. - Infrastructure's code come into a domain logic. - Can not change a middleware, backend services and data storages easily. - Ruin testability for Domain logic. υϝΠϯ͕Πϯϑϥʹґଘͯ͠͠·͏ͷ͕໰୊ɻ
  25. Layers structure 34 Interface Application Domain Infrastructure The Domain centered

    Architecture Domain is free. (No any depends) - Eliminated side effects in domain models. - However, Application remains Infrastructure dependent. υϝΠϯ͕Πϯϑϥʹґଘ͠ͳ͍ɻ
  26. Layers structure 35 - Same basis with the Hexagonal Architecture

    and Clean Architecture. ͞ΒʹਐΊͯΦχΦϯΞʔΩςΫνϟɻ The Onion Architecture : part 1 http://jeffreypalermo.com/blog/the-onion-architecture-part-1/
  27. Layers structure 36 Interface Application Domain Infrastructure Domain and Application

    are not depends on Infrastructure. - Infrastructure mixed-in into the Application and Domain by the Interface. The Onion Architecture ΞϓϦέʔγϣϯ΋Πϯϑϥʹґଘ͠ͳ͍ɻ
  28. Error handling 38 Don't throw an Exception. - In Functional

    programming, Exception is side effect. - Returning a value that wrapped with Error-type. - Unify the Error-type for easy error handling. Τϥʔ͸ྫ֎Ͱ͸ͳ͘ɺ໭Γ஋Ͱฦ͢ɻ
  29. Error types Option Some(value) or None Try Success(value) or Failure(Exception)

    Either Right(value) or Left(value) 39 Error-types in Scala. 4DBMBͰ࢖͑ΔΤϥʔܕɻ
  30. Error types 40 scala.Option Used to express a optional value

    in domain concept. Can not have a error content, so do not used to error handling. - Optional properties of the Entity and Value Objects. - An Entity may not found in the Repository's finder methods. ( >( > )( > >= ( = > > > : > >= > >= 0QUJPO͸Τϥʔॲཧʹ͸࢖Θͳ͍ɻ
  31. Error types 41 scala.util.Either Can returning a error contents if

    the Domain contract was not complied. Define a custom error type, and use it with Either. - Use in error handling on Domain and Application. - The custom error type is desirable to have a stack trace. == : C,= ( C > = = C = C C A == : C > C = C > > = C C = C) > C C A Τϥʔॲཧ͸ &JUIFSͰɻ
  32. Error types 42 scala.util.Try Can wrap a Java's Exception, and

    return it as a return value. - Enclose the code that may throw an Exception with `Try{...}`. - Useful when using any Java libraries in the Infrastructure, because these throw an Exception. : ( ) = > : = > +BWBϥΠϒϥϦΛ࢖༻͢Δͱ͖͸ 5SZͰғΉ ɻ
  33. Error handling 43 Errors at the Layers - Violation the

    Domain contract. - Mainly, cause by user's operation, and resolvable by self. - Unexpected error such as a failure at Storage, N/W and other Services etc. - Could not resolve by user. - Could not complete the Use-Case. - Mainly, cause by user's operation, and resolvable by self. - Invalid input. - Cause by user's operation, and resolvable by self. Infrastructure Layer Interface Layer Application Layer Domain layer ֤ϨΠϠʔ͝ͱͷΤϥʔͷಛੑɻ
  34. Error handling 44 Converting the Error Want return the Error

    user friendly(What?, Why?, How to solve?), but should not be conscious the Interface at the Domain and Infrastructure. An Error from the Domain and Infrastructure need convert to user friendly Error. ϢʔβʔϑϨϯυϦʔͳΤϥʔʹม׵͢Δඞཁ͕͋Δɻ
  35. Error handling 45 Interface Application Service Repository Event Publisher Repository

    Impl Event Pub. Impl Domain Service Entity Factory Query Processor Query Proc. Impl Java lib. Ex) JDBC driver Exception Try Either [Domain Error] Either [Service Error] Convert to Try. Convert to the Service Error from Domain Error and Try. ϨΠϠʔ͝ͱʹΤϥʔܕΛม׵͍ͯ͘͠ɻ
  36. Error handling 46 Convert at Application Service Convert to the

    Service Error(Either) at Application Service. - From a Domain Error(Either). - From an Infrastructure Error(Try). Define some helper function for converting a errors at Application Service like as the Use-Case specification. ΞϓϦέʔγϣϯαʔϏεͰΤϥʔม׵Λࣗવʹɻ
  37.  Error handling 47 I. - F <.=. I I

    IF = IF I = I I < EI = I<= I IIIIIIIII = = E ( I = = = < = I = I I = <I = I= < . < <.= I ) . < - = I = I I < I = I= . = = E < . < E I . < - = /IIIIIIIIIIII < < . < I . < - = IE I . Τϥʔॲཧͷίʔυྫɻ
  38. 49 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Components ίϯϙʔωϯτɻ
  39. 50 Intention The application code is the Use-Case specification. -

    The Application service is a client of the domain, and a mirror to reflect that's expressiveness. - Writing the Application services naturally using the ubiquitous language. ΞϓϦέʔγϣϯαʔϏε͸Ϣʔεέʔεهड़ɻ
  40. 51 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Application Service ΞϓϦέʔγϣϯαʔϏεͷ࣮૷ɻ
  41. Application Service 52 - Realize a Use-Case using the Domain

    models. - Just using the Domain models. Do not leak a Domain knowledge out to the Application Service. - Do not depends on the Infrastructure. Even if you change infrastructure, use case specifications are not affected. - Easy to Unit test at Use-Case level. - Transaction boundary. POINT υϝΠϯΛ࢖ͬͯϢʔεέʔεΛ࣮ݱ͢Δɻ
  42. Application Service 53 - Typically, Step of Application Service is…

    1. Get an existing Entity using the Repository, or newly create it using the Factory. 2. Apply some business rule by the Entity or Domain Service. 3. Persist a processed Entity. 4. Publish a Domain event using the Event Publisher. - Combine these steps in `for` expression. - Convert to an Error of Use-Case level from the Domain and Infrastructure errors. POINT Ұ࿈ͷॲཧεςοϓΛɺGPS಺แࣜͰͭͳ͛Δͷ͕جຊܗɻ
  43. Application Service 54 E <E = < > F .

    <E . <E > E =. <E =. <E > E =( E-F >< =( E-F >< E = = FE EI < >< <E F <E, = FE F . <E : E FE < E(I< E E) F ( E = FE E = = E =. <E E = E<E < ) <>F < ( E =( E-F >< F >< E = E < ) <>F < ( < > = EXAMPLE ΞϓϦέʔγϣϯαʔϏεͷίʔυྫɻ
  44. 55 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Entity ΤϯςΟςΟͷ࣮૷ɻ
  45. Entity 56 - Typically, One Entity in the Aggregate. (as

    Aggregate Root) - Identified by unique Entity-ID. Override #equals() and #hashCode() to guarantee equality by it. - Using the Value Object for properties. Do not use primitive types. - Hold only the Entity-ID for association with other Aggregates. Do not hold a Entity instance. POINT ΤϯςΟςΟ͸Ұҙͳ*%Ͱࣝผ͞ΕΔɻ
  46. Entity 57 - Define the Domain behavior as Entity's method.

    Do not become the "Anemic Domain Model" !! - Entity's method is return a modified Entity and a Domain event. Do not rewrite a own states. - If improper as the Entity's method, implement to Domain Service. (Such as processing that over multiple Entity instances …etc) POINT υϝΠϯශ݂঱ʹͳΒͳ͍Α͏ʹ஫ҙʂ
  47. Entity 58 : ) A A ,A A A =

    ) . ) = A = A E := ( A : D := = :A := E C : A = D A A ,A A := C : C A := A A = :A A C A EXAMPLE ΤϯςΟςΟͷίʔυྫɻ
  48. 59 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Value Object όϦϡʔΦϒδΣΫτͷ࣮૷ɻ
  49. Value Object 60 - All nouns in the Domain are

    define a type as the Value Object. - Type alias is not type safe. - Extends `scala.AnyVal`. By this reduce cost when instantiate Value Objects. - Define the First-class Collection for collection of objects. Do not use raw Collection(List, Set, Map…). POINT υϝΠϯͷ໊ࢺ۟͸όϦϡʔΦϒδΣΫτܕΛ࡞Δɻ
  50. Value Object 61 - Automatically convert with Value Object and

    primitive type using `implicit conversion` and `Type-class pattern` at the Interface and Infrastructure for reduce implementation cost. POINT ϓϦϛςΟϒ஋ͱͷ૬ޓม׵͸Ͱ͖Δ͚ͩࣗಈԽɻ
  51. Value Object 62 E N A FN A NL :

    N F N FFN F - N E A N A FN A N N = F N F E N FFN F N E A NN N A = N F L F N = N C A A FN F / - ) F N = N( F A FN F ( ) F N FFN( A N E A N A FN A F N FFN( A F A F N D ( A NLNN N+ EF FFN( A : A N( A N N C A FN N A FN "N A EXAMPLE όϦϡʔΦϒδΣΫτͷίʔυྫɻ
  52. Value Object 63 <:OC >: O= E E E:O O

    C I:E O/E= = =I:O :O )O :O. >: = = = : E : /"O O O : / I : O/ = = = C I O/O()O O O(O C I I : O C I:E O :O. >: O )O/E= = =I:O : = = = : E : / I : O : / O/O(OI : I : N = CE O= E E E: = = = I C - : O E= <O()O - : (O I O()O , I I - : O - : (O : OO O C I:E : O C = O CO :O. >: I E - : O E= <O(O - : O C I:E : O C = O CO E= = =I:O : EXAMPLE όϦϡʔΦϒδΣΫτͷίʔυྫɻ
  53. 64 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Role ϩʔϧͷ࣮૷ɻ
  54. Role 65 - (Maybe)Not defined as the Component in the

    DDD. - Define the relationships between the Entities across Aggregates. POINT ू໿Λ·͙ͨΤϯςΟςΟͱΤϯςΟςΟͷؔ࿈Λఆٛɻ
  55. Role 66 POINT - Define the Role by the role

    name of relationship. - Can define a methods to handle relationship without modify targeted Entity. - Convert automatically to the Role from targeted Entity using by `implicit conversion`. - Can write code with Role as the subject by SVO style. ؔ࿈ઌͷΤϯςΟςΟʹӨڹͤͣʹؔ࿈Λѻ͏͜ͱ͕Ͱ͖Δɻ
  56. Role 67 / = / / , = , =)

    D / / / ) : ) , =) : : , = / : ) : # D ( : / / : / . / # : A , = : # / / : = , = : # : = D D EXAMPLE ϩʔϧͷίʔυྫɻ
  57. Role 68 = /: ) /: ( = ./ /

    / / /.( = /: ./ /. / / / /: / / : / : /.( = /: ( EXAMPLE ϩʔϧΛ࢖͏ίʔυྫɻ
  58. 69 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Factory ϑΝΫτϦͷ࣮૷ɻ
  59. Factory 70 - 2 patterns for creation the Entity. 1.

    Created individually. 2. Created by a Entity in other aggregation. (If necessary to hold that Entity ID) - In individual case, create a Entity by the Factory. The Factory implement as the Companion object of the Entity. - In other aggregation case, create a Entity by the Role. POINT ΤϯςΟςΟੜ੒ͷͭͷύλʔϯɻ
  60. Factory 71 - The Factory is responsible for generating a

    unique Entity ID for each new Entity. - In many cases, ID generation method is depends on Infrastructure, so give the ID Generator to the Factory from outside. - By doing so easy to Unit-test for the Factory. POINT ΤϯςΟςΟ*%ͷੜ੒ϩδοΫ͸֎͓ͩͯ͘͠͠ɻ
  61. Factory 72 /: / / :/ . . " /

    . / = A . /A / . / : A ) /A= ( A AE ) /A= . . ) /A= " / / G /: . /A . / / = ,A / /A = / / :/ / / " / / / " / A = . : A :/ A = . /A / / / / : A ) /A= ( A AE ) /A= / / ) /A= " / / " / A = G /: A/ /A / / / ( / : A/ EXAMPLE ϑΝΫτϦʔͷίʔυྫɻ
  62. 73 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Repository ϦϙδτϦͷ࣮૷ɻ
  63. Repository 74 - Persist a Entity including Value Objects. -

    Define the interface(trait) with the Domain, and implement it with the Infrastructure. - Typically, in addition to the following methods and it have some finder methods. 1. Get an Entity by Entity ID. 2. Persist an Entity. (INSERT or UPDATE) 3. Delete an Entity. (Do not define if it can not be deleted) POINT ΤϯςΟςΟΛऔಘอଘ࡟আ͢Δɻ
  64. Repository 75 - Handle only the Entity in own Aggregate.

    if need handle with the other Aggregate, define as the Query Model. - In the Repository implementation, mutual conversion between a Value Object and primitive type frequently. So convert automatically using `implicit conversion` for to be easier. POINT ू໿Λ·͍ͨͰӬଓԽͯ͠͸͍͚ͳ͍ɻ
  65. Repository 76 = " B B B B ) /

    / B B E B B / B B B / B I B D D " " B B B B B B ( D E B " . D : B " = B D D " = B D D " B " B ) / / B I B E B B / B I B B / B I I EXAMPLE ϦϙδτϦͷίʔυྫɻ
  66. 77 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Domain Service υϝΠϯαʔϏεͷ࣮૷ɻ
  67. Domain Service 78 - Collection of any functions that is

    defining business rule of the Domain. - Not the Façade. Without using Repository and Event Publisher, and do not occur side effects. - Not required. Define if necessary, such as realize complex business rules. POINT ϑΝαʔυͰ͸ͳ͍ɻؔ਺ͷू·Γɻ
  68. Domain Service 79 ) ( . ( : . (

    ( ( = ( ( ( = ( ( ( . ( : . ( EXAMPLE υϝΠϯαʔϏεͷίʔυྫɻ
  69. 80 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Domain Event and Event Publisher υϝΠϯΠϕϯτͱΠϕϯτύϒϦογϟʔͷ࣮૷ɻ
  70. Domain Event, Event Publisher 81 - Define each business events

    in the Domain knowledge as the Domain Event. (such as "Created a Task", "Change a title of Task" etc...) - In the CQRS(Command Query Responsibility Segregation) Pattern, update the Query Model asynchronously via subscribe the Domain Events. - In the Micro-Service Architecture, using Domain Events for collaborate with other Services asynchronously . POINT υϝΠϯͰى͜Δࣄ৅ΛϞσϧԽ͢Δɻ
  71. Domain Event, Event Publisher 82 - Do not hold the

    Entity. Define only necessary properties. Because, should not recreate the Entity from a Domain Event. - Domain Event is created and returned with return value by the Entity or Domain Service. - Event Publisher is deserialize(such as JSON, XML) the Domain Event and queue to a Event queue. POINT υϝΠϯΠϕϯτ͸ΤϯςΟςΟΛอ࣋ͯ͠͸͍͚ͳ͍ɻ
  72. Domain Event, Event Publisher 83 = : C A C

    C ( C = = DC A . A ( = : , D C ) )/) C:C ) E C )/) DC A I , CDA A C ) C:C ( = : )E C A C I ( = : , D C A C E C I ( = : , D C C A C C : C = C DC A EXAMPLE υϝΠϯΠϕϯτͷίʔυྫɻ
  73. Domain Event, Event Publisher 84 C) : = ( :

    : = C) : C) ) : . C : . : C) : = ( : :C) : = ( : : = C) : C) ) : C C C EXAMPLE ΠϕϯτύϒϦογϟʔͷίʔυྫɻ
  74. 85 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Query Model and Query Processor ΫΤϦϞσϧͱΫΤϦϓϩηοαʔͷ࣮૷ɻ
  75. Query Model, Query Processor 86 - The Query Model can

    define a view that included values of multiple Aggregation. - The Query Model is updated asynchronously by the Event Subscriber. - Do not use the Value Object for the Query Model. - The Query Processor defines some methods to search the Query Models. This does not have mutator methods. POINT ΫΤϦϞσϧͰ͸ෳ਺ͷू໿Λ·͍ͨͩϏϡʔΛఆٛͰ͖Δɻ
  76. Query Model, Query Processor 87 : . , , =

    , : , : , . ) = = = , , : : ) = = ( , E ) = = = , , : I EXAMPLE ΫΤϦϞσϧͱΫΤϦϓϩηοαʔͷίʔυྫɻ
  77. 88 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Event Subscriber ΠϕϯταϒεΫϥΠόʔͷ࣮૷ɻ
  78. Event Subscriber 89 - Subscribing the Domain Events asynchronously. -

    Execute any process like the following… 1. Update the Query Model. 2. Make a Copy of other Context for using in own Context. - Implementing the Event Subscriber depends on the Infrastructure using as Event queue. (such as AWS Kinesis, SQS and Lambda) POINT υϝΠϯΠϕϯτΛड৴ͯ͠ඞཁͳॲཧΛ͢Δɻ
  79. 90 Factory Repository Domain Service Query Processor Query Model Event

    Publisher Application Service Interface Entity Value Object Role Domain Event Event Subscriber Interface ΠϯλʔϑΣʔεͷ࣮૷ɻ
  80. Interface 91 - Provide any boundary for the user and

    other Services. (such as GUI, CLI, API …etc) - Validate input value, and execute the Use-Case using the Application Service. - Choose implementation of the Infrastructure to use, and inject to the Application Service and more. - The implementation of the Interface depends on the framework used. POINT Ϣʔβʔ΍ଞγεςϜ΁ͷΠϯλʔϑΣʔεΛఏڙɻ
  81. Interface 92 D N E )BA DB D E D

    N E D : C N E D D . I E E . C "N E D, EEN E )BA DB D, C A EN E )BA DB D N,AE A N N CC BAN D N A N A= N C A A E B DD N E D NA IN E D I N D AE BA I D B DD N E D CBE BDK NA IN E D CBE BDK I N E D CBE BDK/A ( B DD N E CBE BDK NA IN E CBE BDK I N E CBE BDK/A ( B DD N E A E D NA IN E A E D I N E A E D/A : EXAMPLE ΠϯλʔϑΣʔεͷίʔυྫɻ
  82. And more… 95 - with the Event Sourcing No update

    an Entity states, records all Domain events. Can re-create a Entity by replaying recorded Domain events. - with the Reactive programming Integrate the reactive programming with DDD using the Akka(Stream). Πϕϯτιʔγϯάͱ͔ϦΞΫςΟϒϓϩάϥϛϯάͱ͔ʜ
  83. Require incremental learning 96 - No substitute for practicing DDD.

    - Establishing own(ours) style by practice, experiment and learning cyclically. - Practice gradually while consult own(ours) skill sets… - Easy to practice incrementally with the Micro Service Architecture, because can practice per a bounded contexts. %%%ͷ࣮ફ͸ܧଓతͳֶश͋ΔͷΈɻ