George
10/05/2022, 8:45 AMclass ServerError private constructor(val message: String, val code: Int) {
fun <T> toErrorPayload(): HubPayload<T> = errorPayload(message, code)
}
In this case the function toErrorPayload
(for the sake of example ignore the HubPayload return type :)) naming prefix convention shouldBe to
or as
. Since im returning another object i guess the default is to
, but if i want to emphasize that the values remain the same, just the wrapper is changing then should i name it asErrorPayload
? Thanks in advance for any answers !Javier
10/05/2022, 8:49 AMto
, I only use as
when to
is already there, i.e, toString()
. I have seen this behavior in some popular libs but I would like to know more opinions toophldavies
10/05/2022, 8:50 AMas
as a view of the value in the alternative shape with to
being a copy in the alternative shape.phldavies
10/05/2022, 8:51 AMto
. As an aside I'd probably declare it as an extension method unless the conversion truly belongs to the class.