I need to create 4 subclasses of an abstract class...
# getting-started
g
I need to create 4 subclasses of an abstract class whose sole constructor has 7 parameters (3 of which are required). Is there a way to avoid having to replicate the parent class' contructor signature so many times?
This is what I'm having to do:
Copy code
class Child(
    recipientAddress: String,
    payload: ByteArray,
    senderCertificate: Certificate,
    messageId: String? = null,
    creationTime: ZonedDateTime? = null,
    ttl: Int? = null,
    senderCertificateChain: Set<Certificate>? = null
) : Parent(
    recipientAddress,
    payload,
    senderCertificate,
    messageId,
    creationTime,
    ttl,
    senderCertificateChain
) {
// stuff
}
s
if they’re not explicitly private to the parent you could make them override-able properties
g
Thanks Shawn! Wouldn't that skip any validation done in the
Parent
constructor?
s
uhh yes it would lol, if validation is stricter than just types then, yes, you’re stuck with this approach unfortunately
g
OK. Thanks for your help!
a
maybe some composition would be in order here? Maybe some of the fields can be split into smaller classes?