Singleton class: static properties or non-static properties?

I am programming a class that acts like Singleton. I was wondering if it makes sense to have non-static properties for this class?

Pseudo-code example:

class Foo extends MySingletonClass {

    private static string bar;
    private string baz;

    /* more code here */

}
+3
source share
1 answer

It is wrong to have static properties, but it is redundant in singleton mode.

In addition, if you have static properties, and later you need to change the class so that it is not superfluous, you will also need to change the properties (like every code that accesses it). Therefore, I recommend that you do not mark as static if it is really necessary.

+4
source

All Articles