Our company’s best practice is to create all domain classes with public getters, but private setters - using explicit functions to make modifications to the domain’s state. In kotlin, we have been able to achieve this purpose with code looking like the following:
class Vehicle(
vehicleId: Int?,
stateCode: String,
licensePlate: String?,
vin: String?,
makeCode: String,
colorCode: String,
typeCode: String?,
campusOwnerByuId: String?,
campusTagCode: String?,
primaryVehicleFlag: Boolean,
allowNewOwner: Boolean,
stateOwnerId: String?,
stateTagCode: String?,
campusUseCode: String?,
nickname: String?,
vehicleYear: String?,
campusRelationToOwner: String?
) {
var vehicleId = vehicleId
private set
var stateCode = stateCode
private set
var licensePlate = licensePlate
private set
var vin = vin
private set
var makeCode = makeCode
private set
var colorCode = colorCode
private set
var typeCode = typeCode
private set
var campusOwnerByuId = campusOwnerByuId
private set
var campusTagCode = campusTagCode
private set
var primaryVehicleFlag = primaryVehicleFlag
private set
var allowNewOwner = allowNewOwner
private set
var stateOwnerId = stateOwnerId
private set
var stateTagCode = stateTagCode
private set
var campusUseCode = campusUseCode
private set
var nickname = nickname
private set
var vehicleYear = vehicleYear
private set
var campusRelationToOwner = campusRelationToOwner
private set
}
But I’m sure I don’t have to tell you how monotonous this can get for all of our objects… And we aren’t able to use data classes. It would be really nice to have something like:
data class Vehicle(
private (set) vehicleId: Int?,
private (set) stateCode: String,
private (set) licensePlate: String?,
private (set) vin: String?,
private (set) makeCode: String,
private (set) colorCode: String,
private (set) typeCode: String?,
private (set) campusOwnerByuId: String?,
private (set) campusTagCode: String?,
private (set) primaryVehicleFlag: Boolean,
private (set) allowNewOwner: Boolean,
private (set) stateOwnerId: String?,
private (set) stateTagCode: String?,
private (set) campusUseCode: String?,
private (set) nickname: String?,
private (set) vehicleYear: String?,
private (set) campusRelationToOwner: String?
)
like is done in Swift to help out with creating data classes with private setters.