윤동환
03/16/2023, 3:17 AMfun Order.createAnotherDomain() {
// some validation logics...
return AnotherDomain(
// some parameters
)
}
but i have another choice, companion object`s factory method…
class AnotherDomain {
companion object {
fun from(order: Order) {
// some validation logics...
return AnotherDomain(
// some parameters
)
}
}
}
so what is the appropriate way to create another domain class? i feel using the extension function looks like more readable and simple. i’m asking your opinion!Josh Eldridge
03/16/2023, 4:25 AMGoetz Markgraf
03/16/2023, 6:51 AMreturnsOrder()
.createAnotherDomain()
.doStuffWithOtherDomain()
...
In functional languages like Haskel or F# you would place this parameter last so that you can use a pipe operator:
returnsOrder
|> createAnotherDomain
|> doStuffWithOtherDomain
Extension Functions can be used as a “Kotlin replacement” for this.Stephan Schröder
03/16/2023, 1:17 PM윤동환
03/25/2023, 4:08 AM