I am new to DDD, and even after reading the blue and red books, I still have some questions about how to convert some principles into code, in particular using Kotlin and Java.
For example, I identify the root of the client aggregate, which receives some parameters necessary for creation, for example, Name and Address:
class Client: AggregateRoot {
var clientId: ClienteId
var name: Name
var address: Address
constructor(name: Name,address: Address) : super(){
this.name = name
this.address = address
}
The simple part: To create a new client, I get a DTO inside the RS service and try to create a new Client class that passes the above parameters if everything was strong and all the rules are followed. I am sending a new client instance to the repository, pretty direct. / p>
clientRepository.store(client)
:
, , , .
override fun getById(id: Long): Client {
val clientEntity = em.find(...)
val client: Client(.....)
return client
}
, , ClientId
constructor(clientId: ClienteId,name: Name,address: Address) : super(){
, , :
- . #, .
- - Java Kotlin, , ?
: , , , , :
client.addAddress(address)
, .