EntityObject
Marks a class as a domain entity in domain-driven design (DDD).
Entities are objects that have a distinct identity that runs through time and different states. They are defined by their identity rather than their attributes, and they can be mutated while maintaining continuity of identity.
Key characteristics of entities:
Have a unique identity that distinguishes them from other entities
Can change state over time while maintaining identity
Are mutable and can be modified through business operations
Often contain business logic and validation rules
Example usage:
@EntityObject
class Order(
@AggregateId
val orderId: String,
var status: OrderStatus = OrderStatus.PENDING,
val items: MutableList<OrderItem> = mutableListOf()
) {
fun addItem(item: OrderItem) {
// Business logic for adding items
items.add(item)
}
fun cancel() {
require(status == OrderStatus.PENDING) { "Can only cancel pending orders" }
status = OrderStatus.CANCELLED
}
}Content copied to clipboard
See also
for aggregate root entities
for immutable value objects