is there a not so verbose way to define a class th...
# announcements
i
is there a not so verbose way to define a class that contains all the fields from another + a new one (I don't care if it's via inheritance, composition)
j
is the class you want to add to
open
?
i
I can make it open yes
j
is extension too verbose?
Copy code
open class A {}

class B(val a: Any): A()
i
my problem with verbosity is when
A
has a few fields
then you have to list them all in the constructor of B and pass to
A()
as well
j
sure, if they need passing in, they need passing in somewhere..
i
also, ideally
A
should be a data class...
(and
B
as well. I could also model both as case classes from a sealed class)
(and put the common fields in the sealed class)
j
hmmm does B want to be a data class also?
s
Copy code
interface Notitication
interface ProgressNotification : Notification { 
val extra: Any
}

data class WithProgress(override val extra: Any, private val notification: Notification) : ProgressNotification, Notification by notification
Something like this ?
i
crossed my mind too, but I think that it doesn't help with verbosity... 🙈
as now the fields would have to be declared in
Notification
and then again in the default notification class...
j
Copy code
data class A(val field: Any)

data class B(val a: A, val otherField: Any)
but then awkward to grab the internal fields 😞
i
in the later A and B aren't related though
I need to be able to match
j
I think the interface/delegation is probably your best bet.
👍 1
i
yeah was thinking that too. Will try it out
thank you!
j
but maybe someone more Kotlin-literate will have a better suggestion!
i
I doubt that there's anything else 😄
s
Either that or relax the requirement that
NotificationWithProgress
needs to be a
Notification
also and just pass it manually
i
yeah but then my notification parameter would have to be an "any"?
considering a function that accept these notifications as parameters
and matches on them
ok... trying out the delegate