Паттерны / Порождающие паттерны
image

//Prototype
interface Shape {
    fun clone(): Shape
}

//ConcretePrototype
class Square(var lineCount: Int = 4): Shape {
    override fun clone(): Shape {
        return Square(lineCount)
    }
}

//Client
class ShapeMaker(private var shape: Shape) {
    fun makeShape(): Shape {
        return shape.clone()
    }
}

val square = Square()
val maker = ShapeMaker(square)

val square1 = maker.makeShape()
val square2 = maker.makeShape() as Square

println(square1)
println(square2.lineCount)


Описывает виды создаваемых объектов с помощью прототипа и создает новые объекты путем его копирования.