Hi Danny Preussler,

yes if you have more than one Viewholder you can’t go without an if/switch. Something like:

fun forType(parent: ViewGroup, viewType: Int) : ViewHolder {
when(viewType) {
in listOf(R.layout.duck, R.layout.dog, R.layout.mouse) -> return AnimalViewHolder(parent)
else -> return CarViewHolder(parent)

For me this function should be in the same class that knows all the types, like the visitor implementation. So it becomes like a factory. This way you don’t split all the types all over the place.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.