As of now java.util.UUID is used for all kinds of identifiers in Axon.
Nothing wrong with this, but it makes some things harder, at least in
my code.
Before I started using Axon a typical constructor would look like:
public Order(
final OrderId id,
final ShareId shareId,
final ParticipantId participantId,
final LocalDateTime timestamp,
final Side side,
final Money price,
final Volume volume)
)
Now (Order, Share and Participant being agregate roots) it looks like
this:
public Order(
final UUID id,
final UUID shareId,
final UUID participantId,
final LocalDateTime timestamp,
final Side side,
final Money price,
final Volume volume)
)
This is because java.util.UUID is final and OrderId cannot inherit it,
which would otherwise solve the problem.
Wouldn't it be possible to have this instead?
// In Axon
////////////////
/**
* Use this instead of UUID everywhere
*/
public interface UniqueIdentifier {
// Nothing needed here. equals, hashcode and toString inherited
from java.lang.Object.
}
public class UUIDIdentifier {
private UUID identifier;
public UUIDIdentifier(UUID identifier) {
this.identifier = identifier;
}
@Override
public boolean equals(Object o) {
return this.identifier.equals(o);
}
@Override
public int hashcode() {
return this.identifier.hashcode();
}
@Override
public String toString() {
return this.identifier.toString();
}
}
// In my project
///////////////////
public class OrderBookId extends UUIDIdentifier {
public OrderBookId(UUID identifier) {
super(identifier);
}
}