33
loading...
This website collects cookies to deliver better user experience
Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity.
An object primarily defined by its identity is called an Entity.
status
attribute (like pending
, active
, or inactive
) or attribute prefixes like current
or last
.Student
will be the same student if attributes like email
or even name
change. It is important to define what it means for a student to be the same student. Maybe it would be something like matriculationNumber
or just a generic id
. The following image shows a potential class diagram for this application, which I'll use as an example from now on.Student
Entity (for simplicity the Course
is committed as it isn't really required to prove my point later on):Be alert to requirements that call for matching objects by attributes.
@Entity
is used for Entities.)Many objects have no conceptual identity. These objects describe some characteristics of a thing.
An object that represents a descriptive aspect of the domain with no conceptual identity is called a Value Object. Value Objects are instantiated to represent elements of the design that we care about only for what they are, not who or which they are.
Student
could have an Address
, which consists of street
, streetNumber
, postcode
, and city
. In the domain of our application, the address would be a VO. Changing one of the attributes would make it a different address. An address is more like a complex attribute type (instead of a primitive data type like string, boolean, etc.) of an Entity (or other VOs; in this case of the Entity Student
). Address
VO, but if one of the students moves somewhere else we don't want to mutate that instance because that would affect the other student as well. Instead, we end up creating a new Address
instance (or reusing an existing instance of that address if it exists). Sharing a VO instance is shown in the next image. It also showcases the VO being like a complex attribute because it is ending up in the same row in the database in this case.@Embeddable
(1:1) and @ElementCollection
(1:n) are used for VOs).33