Domain-Driven Design with Golang by Matthew Boyle BIRMINGHAM—

Domain-Driven Design with Golang by Matthew Boyle BIRMINGHAM—

Author:Matthew Boyle BIRMINGHAM—
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2022-12-02T00:00:00+00:00


The service is small. We call our validateAndEnrich function to mutate the purchase object for us to add some necessary values. We could also have made Purchase both a value object and an entity, which would have meant we did not need to mutate.

After calling purchase.validateAndEnrich(), we have some logic depending on the payment means. If it’s a card, we call CardService to create the purchase. We don’t have CardService defined yet, so for now, we are creating an interface.

Let’s imagine that your team has split into two halves. One half is working on payments, and the other on implementing purchases. We could meet with the payment team and agree on a contract for what CardService will look like (in Go, we call these contracts interfaces), and then we can continue with our implementations at separate paces. This is a really powerful pattern so use it often when working with other teams!

Finally, if all goes well, we call PurchaseRepo to store our new purchase.

We define repository.go inside the purchase package:



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.