What the abstrac final class mean?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Aug 12 10:25:11 UTC 2019

On Monday, August 12, 2019 2:54:56 AM MDT lili via Digitalmars-d-learn 
> Hi:
>      Why need defined an abstract final class?
>      see
> https://github.com/Rikarin/Trinix/blob/master/Kernel/arch/amd64/gdt.d

It's one way to effectively create a namespace using a class. Another way
would be to declare the class final, @disable its default constructor, and
provide no other constructors. Either way, the result is that the class
cannot be instantiated and any static functions declared within the class
have to use the class' name when referencing them, whereas if they were free
functions within a module, a non-static import would allow you to refer to
them directly.

For better or worse, std.datetime does it with the class Clock to force the
functions for getting the time to all refer to Clock - e.g.
Clock.currTime(), whereas if they were directly in the module, it would be
possible to do something like currTime().

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list