Cody Engel
04/03/2020, 2:30 PMsealed class Article {
abstract val title: String
abstract val body: String
abstract val updatedAt: Date
abstract val categories: List<Category>
data class New(
override val title: String,
override val body: String,
override val updatedAt: Date,
override val categories: List<Category>
) : Article()
data class Existing(
override val title: String,
override val body: String,
override val updatedAt: Date,
override val categories: List<Category>,
val id: UUID
) : Article()
}
👋🏻 I’m working on modeling the different states an object could be in (say for GET, POST, PUT, and DELETE) and I’ve landed on this for now. The New variant would be exclusively for POST requests while the Existing would be used for GET, PUT, and DELETE, although the delete would only require the id.
Thoughts?josh
04/03/2020, 6:29 PMCody Engel
04/03/2020, 6:36 PMGET, POST, and PUT is with GET you have the full picture of the model, POST you have the least clear picture since you may delegate the id generation away, similar to PUT where you’d know the id but probably don’t want to allow the caller to say when it was updated. So I am starting to look at having an interface for IDs where they would just be a UUID and then similar to date captures. But still not sure… Modeling these requests is trickier than I thought it would be 😂Cody Engel
04/03/2020, 6:40 PMval and var are delegates in their own right since they are generating the setters/getters for you