When creating classes that implement interfaces fo...
# language-proposals
j
When creating classes that implement interfaces for use as delegates - it would be great to be able to mark them as incomplete and have compile-time error if the class using it as a delegate didn’t override any unimplemented methods. Is there a way to do that at the moment?
k
Doesn't making those methods abstract work?
j
Can you make a method abstract? I’ve tried making the implementation class abstract, but then you can’t say
SomeInterface by SomeImplementation()
because
SomeImplementation
is abstract and cannot be instantiated.
I currently throw not implemented in the methods I want the composed classes to implement.
d
You cant implement a part of an interface, create an instance and then delegate to that instance. And that will never be possible.
Unless they add some really weird stuff to the compiler that I dont see them adding.
Dont you think it would make more sense to put this in #general ?
j
Maybe - I’m new here so could be wrong. I thought this was best for proposing some method of allowing something that currently isn’t possible.
d
Fair enough :)
You cant create an instance of a class that isn't concrete, I.e. abstract. Proposing that this should be possible is inevitably going to get turned down. Because it's an inherent property of abstract classes.
j
maybe like
Copy code
class MyClass :
    SomeInterface by Compose<AbstractImplementation, MyClass>() {
// Must override parts of SomeInterface not implemented in AbstractImplementation
}
or alternatively you could compose two different abstract implementations if they don’t overlap, or perhaps have some rule for which one gets used if they do overlap.
d
That would require multiple inheritance which is again not possible right now because you would inherit
Any
twice (diamond problem).
Inheritance isn't a case of copying members
j
No.. it would create a new class, internally named something sensible, composed at compile time by using methods from the AbstractImplementation and MyClass or whatever else you specified there.
d
Okay, that could be a feature.
Feel free to try and convince everyone that it would be worthwhile
t
If I am understanding you correctly something like this (https://pl.kotl.in/BkoJRn5PV) could help you, but only with this (https://github.com/Kotlin/KEEP/issues/155) KEEP proposal.
j
Yeah that snippet looks like the kind of thing I was proposing. Although the syntax is somewhat cumbersome, to have an object inline in the class header like that. It would be much nicer if you could mark the delegate implementation as incomplete, and provide the rest of it within your class body.