Domain Modeling Made Functional: Tackle Software Complexity With Domain-Driven Design and F# by Scott Wlaschin

Domain Modeling Made Functional: Tackle Software Complexity With Domain-Driven Design and F# by Scott Wlaschin

Author:Scott Wlaschin
Language: eng
Format: mobi, epub, pdf
Tags: Pragmatic Bookshelf
ISBN: 9781680502541
Publisher: Pragmatic Bookshelf
Published: 2017-12-25T00:00:00+00:00


The internal steps

In a separate implementation file (such as PlaceOrderWorkflow.fs) we would put the types used by the internal steps. Later on, at the bottom of this same file, we’ll add the implementation.

We’ll start with the internal states that represent the order lifecycle:

​ ​// bring in the types from the domain API module​

​ ​open​ DomainApi

​ ​// ----------------------​

​ ​// Order lifecycle​

​ ​// ----------------------​

​ ​// validated state​

​ ​type​ ValidatedOrderLine = ...

​ ​type​ ValidatedOrder = {

​ OrderId : OrderId

​ CustomerInfo : CustomerInfo

​ ShippingAddress : Address

​ BillingAddress : Address

​ OrderLines : ValidatedOrderLine ​list​

​ }

​ ​and​ OrderId = Undefined

​ ​and​ CustomerInfo = ...

​ ​and​ Address = ...

​ ​// priced state​

​ ​type​ PricedOrderLine = ...

​ ​type​ PricedOrder = ...

​ ​// all states combined​

​ ​type​ Order =

​ | Unvalidated ​of​ UnvalidatedOrder

​ | Validated ​of​ ValidatedOrder

​ | Priced ​of​ PricedOrder

​ ​// etc​

And then we can add the definitions for each internal step:

​ ​// ----------------------​

​ ​// Definitions of Internal Steps​

​ ​// ----------------------​

​ ​// ----- Validate order -----​

​ ​// services used by ValidateOrder​

​ ​type​ CheckProductCodeExists =

​ ProductCode -> ​bool​

​ ​type​ AddressValidationError = ...

​ ​type​ CheckedAddress = ...

​ ​type​ CheckAddressExists =

​ UnvalidatedAddress

​ -> AsyncResult<CheckedAddress,AddressValidationError>

​ ​type​ ValidateOrder =

​ CheckProductCodeExists ​// dependency​

​ -> CheckAddressExists ​// dependency​

​ -> UnvalidatedOrder ​// input​

​ -> AsyncResult<ValidatedOrder,ValidationError ​list​> ​// output​

​ ​and​ ValidationError = ...

​ ​// ----- Price order -----​

​ ​// services used by PriceOrder​

​ ​type​ GetProductPrice =

​ ProductCode -> Price

​ ​type​ PricingError = ...

​ ​type​ PriceOrder =

​ GetProductPrice ​// dependency​

​ -> ValidatedOrder ​// input​

​ -> Result<PricedOrder,PricingError> ​// output​

​ ​// etc​

We’ve now got all the types in one place, ready to guide the implementation.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.