Паттерны / Структурные паттерны
image

//Subject
abstract class Graphic(protected var fileName: String) {

    abstract fun draw()

    fun getGFileName(): String {
        return fileName
    }
}

//RealSubject
class Image(fileName: String): Graphic(fileName) {

    //Request()
    override fun draw() {
        println("draw $fileName")
    }
}

//Proxy
class ImageProxy(fileName: String): Graphic(fileName) {
    private var image: Image? = null

    override fun draw() {
        getImage().draw()
    }

    private fun getImage(): Image {
        if (image == null) {
            image = Image(fileName)
        }
        return image!!
    }
}

//Client
val proxy = ImageProxy("1.png")
//operation without creating a RealSubject
val fileName = proxy.getGFileName()
//forwarded to the RealSubject
proxy.draw()

println("fileName is $fileName")


Подменяет другой объект для контроля доступа к нему. Заместитель реализует интерфейс первоначального объекта.