concept entity in category design

This is an excerpt from Manning's book Object Design Style Guide.
Composition can be used with a service object, making part of its behavior configurable. It can also be used with other types of objects, like entities (sometimes known as models), where composition is used for related child elements. For example, an Order object that contains Line objects could use composition to establish the relationship between an order and its lines. In that case, a client might provide not a single Line object, but a collection (array) of Line objects.
Entities are the application’s core objects. They represent important concepts from the business domain, like a reservation, an order, an invoice, a product, a customer, etc. They model knowledge that developers have gained about that business domain. An entity holds the relevant data, it may offer ways to manipulate that data, and it may expose some useful information based on that data. An example of an entity is the following SalesInvoice class.
Listing 4.1. The SalesInvoice entity
final class SalesInvoice { /** * @var Line[] */ private array lines = []; private bool finalized = false; public static function create(/* ... */): SalesInvoice #1 { // ... } public function addLine(/* ... */): void #2 { if (this.finalized) { throw new RuntimeException(/* ... */); } this.lines[] = Line.create(/* ... */); } public function finalize(): void #3 { this.finalized = true; // ... } public function totalNetAmount(): Money #4 { // ... } public function totalAmountIncludingTaxes(): Money { // ... } }An entity may change over time, but it should always be the same object that undergoes the changes. That’s why an entity needs to be identifiable. When creating it, we give it an identifier.
Listing 4.2. SalesInvoice gets an identifier at construction time
final class SalesInvoice { private SalesInvoiceId salesInvoiceId; public static function create( SalesInvoiceId salesInvoiceId ): SalesInvoice { object = new SalesInvoice(); object.salesInvoiceId = salesInvoiceId; return object; } }This identifier can be used by the entity’s repository to save the object. Later on, we can use that same identifier to retrieve it from the repository, after which it can be modified again.
Listing 4.3. Using an identifier to modify an entity you created earlier
salesInvoiceId = this.salesInvoiceRepository.nextIdentity(); #1 salesInvoice = SalesInvoice.create(salesInvoiceId); this.salesInvoiceRepository.save(salesInvoice); salesInvoice = this.salesInvoiceRepository.getBy(salesInvoiceId); #2 salesInvoice.addLine(/* ... */); this.salesInvoiceRepository.save(salesInvoice);Given that the state of an entity changes over time, entities are mutable objects. They come with specific rules for their implementation:
The methods that change the entity’s state should have a void return type and their names should be in the imperative form (e.g., addLine(), finalize()). These methods have to protect the entity against ending up in an invalid state (e.g., addLine() checks that the invoice hasn’t been finalized already). The entity shouldn’t expose all its internals to test what’s going on inside. Instead, an entity should keep a change log and expose that, so other objects can find out what has changed about it, and why.
On mutable objects like entities, modifier methods should have a void return type. The changes that occur in such objects can be exposed by analyzing internally recorded events. As opposed to immutable objects, mutable objects shouldn’t have a fluent interface.