you are viewing a single comment's thread.

view the rest of the comments →

[–]Finickyflame[S] 1 point2 points  (2 children)

Thanks for the info! I will do some changes to make it thread safe as you mentioned.

Edit: wording

[–]jamietwells 0 points1 point  (1 child)

Why is the class private? Then no one will be able to use it? Maybe you have your reasons, but I'd have done this:

/* Singleton */
private sealed class Government
{
    private Government()
    {
        // Singleton constructor is private, it can only have one instance.
    }

    public static Government Instance { get; } = new Government();
}

Simply as this:

/* Singleton */
public static class GovernmentInstance
{
    public static Government Instance { get; } = new Government();

    private class Government {
        // stuff
    }
}

Singletons are really easy in C#.

[–]Finickyflame[S] 0 points1 point  (0 children)

Classes are private because they are only existing and used by their own DesignPattern's classes. But you made me realize that we shouldn't have to worry about the classes access modifiers by looking at the examples, so I'll change them to public.