Summary

In this chapter, we started to write a lot of code and learned the basics about implementing domain models in code. We looked at entities and value objects, what are they needed for and how different they are. Explaining the power of value objects took a great deal of this chapters and this topic is vital since value objects are often overlooked. 

We used factory functions to create different ways of constructing value objects. A similar technique can be used to form valid entities, but we were not touching this topic just yet. We also used a domain service to make use of some external services inside our value object, while keeping the domain model itself clean from any external dependencies.

Constraints and invariants that play such important role in keeping the state of the system valid at all times were also discussed, and we used different techniques to implement them.

Finally, we moved on to domain events and implemented some events that we previously only seen on orange stickies, directly in our code. Going forward, we learned how from being a supportive tool, domain events could become the driver for state changed in our model and this lays a strong foundation for us before we move on to event-sourcing.

In this chapter, we also wrote some tests. Writing tests and keeping them actual is crucial in any programming work, but when using DDD and being in an explorative mode inside the model, tests become one of the most important instruments to handle regression and even express and document business rules, as we will look closely into in next chapters.

Since we started to move some of our sticky notes to code, in the next chapter, we will look in how to implement commands and how commands are being the glue between our domain model and the world outside it. In this state, we will learn how to make our model useful by letting people interact with it. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.84.157