Static variables inside instance methods. How to fix it?

I recently inherited a 10-year code base with some interesting patterns. Among them are static variables inside instance methods. Only one instance of the class is instantiated, and I can hardly find a reason to justify the existence of these static variables in instance methods.

  • Have you ever developed instance methods with static variables? And what are your rationales?

  • If this template is considered unsuccessful, then how to fix it?

Note. This question does not apply to Static Variables in Instance Methods

EDIT:

Some reading:

+5
source share
3 answers
  • This is a classic C ++ singleton implementation described in one of Scott Meyers C ++ books.
  • Singleton is a controversial template , so there is no consensus that the monophonic approach is weak or weak.

An alternative to singleton is purely static objects. This question has a good discussion.

+4
source

About the only time when I used static fields in an unstable class was constant.

, , , (, , ). . , , - .

+2

, .

, - , , -, . , , , .

+2
source

All Articles