Muhammad Usman
Muhammad Usman

Reputation: 31

What are Entity Value and Service classes means?

I googled and tried many online links to find out the Entity, values and service classes. But nothing found. Can someone explain with a good example that how to find out such classes from a class diagram?
take this ClassDiagram for instance.

Upvotes: 1

Views: 1021

Answers (2)

Christophe
Christophe

Reputation: 73376

Entities, values and services seem to refer to a Domain Driven Design context:

  • an entity is an object which has its own identity, and keeps its identity despite potential modifications of the values in its fields.
  • a value object is an object which has not an own identity. A value object is defined by the value of its fields. Therefore it should in principle be immutable.
  • A service is an operation that is not of the responsibility of an object (entity or value). THe DDD service is not to be confused with a service layer

In your diagram:

  • all classes have their own ID, which suggest that they are all entities. User_vehicle ssems to have a bad naming. It should be called "Subscription".
  • User and Vehicle seem to be aggregate root, with other entities depending on them. Maintenance and Schedule seem to belong to the Vehicle aggregate. It can be discussed whether User_Vehicle and Reservation would belong to the User aggregate or the Vehicle aggregate.
  • There seem to be no apparent class for value object. A value object would not have an ID that ensures it's identity. However, one could argue that dates are value objects, even if not represented explicitely in the diagram.
  • Maybe I'm too old, but I can recognize no evidence of a service here. All the methods seem to be clearly of the responsibility of the object they belong to. A service could be "Create reservation" or "Start subscribtion": in both cases these go beyond the responsibility of a single object: it would always involve at least two entities.

Upvotes: 2

granier
granier

Reputation: 1789

It is not easy to answer to your question since you do not precise the context.

Entities are classes whose instances are stored in DB, and after you get the three usual rules to store classes in db. see ORM

If you are in JEE context, these classes are annotated by @Entity (almost).

A point, class diagram does not discover or find out classes, a class diagram helps to model your classes, not to find them.

Upvotes: 0

Related Questions