interfaces and contracts - new pattern
Adam D. Ruppe
destructionator at gmail.com
Tue Dec 3 17:19:11 UTC 2019
On Tuesday, 3 December 2019 at 16:03:18 UTC, Ola Fosheim Grøstad
wrote:
> But this doesn't work in D.
That's my point - it is unsound in the static type system and D
correctly rejects it. Might work in a dynamic language, but not
in static.
> Yes, but when do you need to do it? So it is typesafe, but what
> would the use case be?
You could conceivably write a child class that wraps or converts.
For example, perhaps:
class Serializer {
void serialize(Serializable s) {}
}
class ExtendedSerializer: Serializer {
override void serialize(Object o) {
super.serialize(reflectToSerializable(o));
}
}
I probably wouldn't do it that way... and I can't think of a time
I actually used this myself which is why I had to make something
up. But still, it conceivably makes sense.
> I've got a feeling that one could do something interesting with
> such semantics that would make all this variance-stuff
> cleaner... somehow. But I haven't given it a lot of thought.
> Just a feeling. :)
Maybe, I haven't thought a lot of it.
More information about the Digitalmars-d-announce
mailing list