Hello everybody, I have this `Listener`, but I onl...
# android
s
Hello everybody, I have this
Listener
, but I only want to implement one or two methods, not all of methods. So what should I need to change ? Thanks
e
it is the definition of interface. If you dont want to implement all of them you need more than 1 interface
m
Hi, @Sam. Add a default implementation to optional methods.
Copy code
interface Listener {
    fun onSubmitted(text: String) // mandatory
    fun onClickedRightIcon() { } // optional
}
🎉 4
s
Thanks @Efe @Marek Osvald
@Marek Osvald: What’s name of this syntax
fun onClickedRightIcon() { }
?
e
default implementation 🤔
K 2
🎉 1
✔️ 1
d
Default implementation in Kotlin can have problems interacting with Java. You can also use the Adapter Pattern, a open or abstract class that implements both functions but they do nothing. Your concrete class will implement the interface using
by
delegation of your adapter, but only override the functions it needs.
K 2
s
@dewildte: `Your concrete class will implement the interface using
by
delegation of your adapter, but only override the functions it needs. (edited) ` => can you give me some example about that pattern ?
r
I second the Adapter pattern with abstract class