Singleton Object, calling member functions using UFCS (an "ugly?" example) ... better way?

user1234 user1234 at 12.de
Wed Sep 1 19:54:14 UTC 2021


On Wednesday, 1 September 2021 at 16:02:47 UTC, james.p.leblanc 
wrote:
> Dear D-ers,
>
> For simple plotting using a gnuplot process, I have created a 
> singleton object (a stripped
> down minimal working example is below.)
>
> [...]
> 
> **However, those wrapper functions in the gnuplot_mod module 
> looks a bit silly.**
>
> [...]
>
> Any suggestions on a better way are greatly appreciated.
>
> Best Regards,
> James

hello, I'd suggest this:

```d
shared static this() {
     get(); // cache instance before main(){}
            // to get rid of the synchronized() stmt
}

static Gnuplot get() {
     __gshared Gnuplot instance;
     return instance ? instance : (instance = new Gnuplot());
}
```


More information about the Digitalmars-d-learn mailing list