Building a Building - Is the building clean? I'm writing a small game and I use Kotlin for that. I want to model my buildings with the following class:

class Building (
    val name: String,
    val inputs: Array&lt;Resource&gt;,
    val outputs: Array&lt;Resource&gt;
) {}


I want to create multiple instances of this class for the map but I don't want to fill the constructor parameters every time with the same data for the same building. So my idea was to make the constructor private and write creator functions in the companion object. 

class Building private constructor(
    val name: String,
    val inputs: Array&lt;Resource&gt;,
    val outputs: Array&lt;Resource&gt;
) {

    companion object {
        fun createWoodcutter(): Building = Building(
            "Woodcutter",
            arrayOf(
                Resource(ResourceType.WOOD, 1),
                Resource(ResourceType.WORKFORCE, 3),
                Resource(ResourceType.MONEY, 10)
            ),
            arrayOf(Resource(ResourceType.PLANKS, 1))
        )
    }
}


But I don't know if this strategy counts as clean code or is there a better way or design pattern for this?
First of all, I would recommend using a data class. In order to do this, it's better to use List rather than Array (because Array does not support hashCode/equals)

data class Building (
    val name: String,
    val inputs: List&lt;Resource&gt;,
    val outputs: List&lt;Resource&gt;
)


Actually, considering that the order of elements doesn't matter you could use Set or any iterable data structure as well, but my experience is that List is usually the fastest to iterate through.

As for using the companion object, that's entirely possible and will be similar to static factory methods, but I like to go beyond that and have a completely separate factory class for this. The reasoning being that I don't want to tightly couple my Building with the actual data, what if I would like to have two entirely different games in the future that both use the Building ? What if I would like to let the user design their own buildings? Either way, I see many reasons to use a separate factory class/object than use the companion object.

In Kotlin it is as easy as defining an object BuildingFactory.

object BuildingFactory {
    fun woodcutter(): Building = Building(
        "Woodcutter",
        listOf(
            Resource(ResourceType.WOOD, 1),
            Resource(ResourceType.WORKFORCE, 3),
            Resource(ResourceType.MONEY, 10)
        ),
        listOf(Resource(ResourceType.PLANKS, 1))
    )
}


Then you can create instances as easy as BuildingFactory.woodcutter()

Another approach could be to have a configuration data file specifying the buildings available and reading from that file. Then construct a building based on a name.