Sealed classes - would you want them in D?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri May 11 23:51:19 UTC 2018


On Fri, May 11, 2018 at 05:28:48PM -0600, Jonathan M Davis via Digitalmars-d wrote:
> [...] what the OP wants is to have the class be publicly available
> while restricting who's allowed to derive from it, with the idea that
> a particular class hierarchy would have a well-defined set of classes
> that the person who wrote them had full control over rather than
> allowing anyone and everyone to derive from any class in the hierarchy
> except for any final classes at the leaves of the hierarchy.
[...]

I would like to hear of a real-world use case for such a restriction. I
honestly can't think of one that doesn't have a design smell of some
sort.  Isn't the whole point of OOP that user code can extend your
classes to implement functionality you have not thought of, rather than
you needing to implement everything for them?


T

-- 
The best compiler is between your ears. -- Michael Abrash


More information about the Digitalmars-d mailing list