* Juha Nieminen:
I still can't understand why anyone would want to. What is the reason,
from object-oriented design point of view, to make a class final?
I have one example of where you initially want sort of the opposite,
that any derived class is abstract, non-instantiable, until you finally
derive a concrete class at bottom like
struct UserClass: SomeAbstractThingo {}; // Can't be made concrete.
typedef Concrete<UserClass> ConcreteUserClass; // Is concrete.
where Concrete<> applies post-construction final initialization (which
can be virtual), e.g. via a call to a virtual PostConstruct() function
from the Concrete<> constructor, and perhaps also ditto pre-destruction
preparatory cleanup.
The/one way to implement "can't be made concrete" and "is concrete" is
the same as for final class, using a virtual base with limited access.
Now if you could derive from Concrete<> you could override PostConstruct
and not have that override called. So making Concrete<> a final class
helps guarantee correct usage by technically disabling one incorrect
usage. It's an old ideal, that to the degree possible all that's
technically allowed should be meaningful and correct, i.e. capturing the
design constraints via the type system etc. However, that ideal must be
balanced against the ideal of C++ that the programmer should always be
able to do whatever he/she wants, even if perhaps in some contorted way.
So whether to make Concrete a final class is an engineering decision.
Cheers, & hth.,
- Alf