Chapter 3. Creating other objects
This chapter covers
- Instantiating other types of objects
- Preventing objects from being incomplete
- Protecting domain invariants
- Using named constructors
- Using assertions
I mentioned earlier that there are two types of objects: services and other objects. The second type of objects can be divided into more specific subtypes, namely value objects and entities (sometimes known as “models”). Services will create or retrieve entities, manipulate them, or pass them on to other services. They will also create value objects and pass them on as method arguments, or create modified copies of them. In this sense, entities and value objects are the materials that services use to perform their tasks.
In chapter 2 we looked at how a service object should be created. In this chapter, we’ll look at the rules for creating these other objects.