'CQRS, Is it bad practice using the same class/model for write and read
So let's say I have a product order system. I have several classes that may look like this.
data class CreateOrderCommand(
val productId: String,
val productSpec: Specifcation
)
data class Specification(
@Min(0)
val size: Int,
@ColorCodeConstraint
val colorCode: String
)
// my read model
data class ProductOrder(
val orderId: String,
val productId: String,
val productSpec: Specification,
val shippingDate: Date
)
So I'm concerned about Specification class that I use for both write and read. I even put Spring constraint for validation on the write side I'm not sure if it would have any effect on JpaRepository??. So what's the best practice here should I create another Specification class having the same field as the write model or it's fine to reuse them for write and read?
Solution 1:[1]
You should use separate classes for the read and write side because eventually, you will probably want to modify each side independently, so you better implement them separately from the start.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tore Nestenius |