Non-ugly ways to implement a 'static' class or namespace?
Hipreme
msnmancini at hotmail.com
Fri Jan 20 13:38:52 UTC 2023
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear
wrote:
> Hi,
>
> In Java/C# you can create purely static classes.
>
> These are classes whose methods are all static, the classes
> cannot be derived from or instantiated:
>
> ```
> static class Algo {
> void drawLine(Canvas c, Pos from, Pos to) { ...... };
> }
> ```
>
There are 2 solutions for that. One involved doing a private
implementation:
```d
module drawer.impl;
void drawLine(...)
```
Then, you create another file:
```d
module drawer;
public import Algo = drawer.impl;
```
After that, you can use it as `Algo.drawLine`.
With a single file, you can do:
```d
final class Algo
{
@disable this();
static:
void drawLine(...){}
}
```
More information about the Digitalmars-d-learn
mailing list