The factory of factories, ‘Abstract Factory’ makes creating objects that are part of some ‘family’ easy. It is another layer over concrete factories delivering client the factory instance for creating objects of a certain variant.After the Static Factory Method
it’s time for classic Factory
. Factory is very useful and often used construction design pattern. Kotlin has interesting advantage thanks to sealed
and internal
classes, that are missing in Java.Static Factory Methods
known from Java have their place also in Kotlin, although they look and behave a bit different because there is no static
word in Kotlin. Here I’ll try to show how to use companion object
for Static Factory Methods
and more. PS: This whole post was supposed to be about Factory Method
with just a short mention about static factory methods, but the topic becomes more interesting than I thought :)The Builder Design Pattern is one of most popular and useful construction patterns in software engineering. In this post I will try to explain it and show how you can use it with Kotlin. Sadly I often see implementations that are simple translation from Java rather that utilizing cool Kotlin syntactic sugar.