Is there any reason I don't know of why the follow...
# getting-started
h
Is there any reason I don't know of why the following would be inferior to a standard class and constructors? (it is superior in flexibility)
Copy code
interface Foo {
    val a: Int
    val b: Int
    fun sum() = a + b
}

fun Foo(a: Int, b: Int) = object : Foo {
    override val a = a
    override val b = b
}
is it more expensive to instantiate object literals than class instances?
i think i prefer this approach to open classes
plus, you can always implement multiple interfaces, so they're just way more flexible
yeah, so I guess the other aspect of taste here is that I don't want my code filled with various names for the same thing like
BasicFoo
,
FooInterface
,
FooImplementation
, etc
yeah, and that's how lists are written, basically, except the functions are masquerading as constructors, using constructor naming convention