You (OP) seem to be preoccupied with OO design, well, I will say this while thinking about the things of static variables. The basic concept is encapsulation and reuse; then you could take care of reuse, but you almost always want encapsulation. If it is a static variable, it really is not encapsulated, is it? Think about who needs to access it, why and how far you can Hide it from client code. Good projects can often change the insides without significant damage to customers, that's what you want to think about . I agree with Scott Myers (Effective C ++) about a lot. OOP goes beyond the class keyword. If you've never heard of this, find the properties: yes, they can be static, and C # has a very good way to use them. In contrast to the literal use of a static variable. As I hinted at the beginning of this element of the list: think about how not to shoot yourself in the leg later, since the class changes over time, that there are not many programmers when designing classes.
Take a look at this Rx medium that someone mentioned. The threading model used for the situation you described cannot be easily resolved without additional information about using IMHO. Make sure you know what you are doing with threads. Many people cannot understand the threads to save their lives; this is not so difficult, since tread protection can be when the code is (re) used. Remember that controllers often need to be separated from objects that they control (for example, more than one class); if you donāt know, look at the MVC book and buy a gang of four.
Depends on what you need. For many applications, a class that is almost completely filled with static data is good enough; like singleton for free. This can be done very OO. Sometimes you prefer to have multiple instances or play with an injection, which makes it more difficult.
I offer topics and events. The ease of creating code driven events is actually one of the best things about C # IMHO.
Hmm, killing loners ...
In my experience, many of the most common uses that young programmers put on their own are nothing more than the loss of a class keyword. Namely, what they meant as a module with state, pumped into the highlander class; and there are some bad singleton implementations that you can find. Whether this is because they were unable to find out what they are doing, or just Java in college, I donāt know. Returning to Earth, he named the use of data in the file field and provided an API. In C # (and Java) you are attached to the fact that it is a class in more than several languages. OOP! = Class keyword; study lhs well.
A well-written class can use static data to efficiently inject a singleton and force the compiler to do footwork while preserving it, or as one when you ever get something. Do NOT replace inherited singletones if you donāt seriously know what you are doing. Inadequate inheritance of such things results in more fragile code that waaaay knows well. Classes must be dumb, data is smart. That sounds silly if you don't look deep into that expression. Using inheritance IMHO for such a thing is usually bad (tm), languages āāhave the concept of modules / packages for some reason.
If you want it, hey, did you translate it into annuals a long time ago? Sit down and think a little bit: how can I better structure this application to make it work in an XXX way, and then think about how this does the XXX way of influencing things, for example, does it one of the ways that will become a source of disagreement among the threads? In an hour you can go through a lot of things. When you get older, you will learn the best methods.
Here is one suggestion for XXX to start: (visualize) write (^ Hing) a controller controller class that works as a manager on the objects it refers to. These objects were your singles, not a controller, and they are just examples of these classes. This is not the best design for many applications (especially it may be a problem in heavily threaded IMHO), but in general it will solve what motivates most young people to reach one single, and it will be effectively used for a wide range of programs. This is uh, like the CS 102 design pattern. Forget the singleton you learned in CS 607.
This control class, perhaps an āApplicationā would be more appropriate;) basically solves your need for single games and for storing the configuration. How to do this with the sublime OO method (if you understand OOP) and not take your foot off (again) is an exercise for your own education.
If this shows, I am not a fan of the so-called singleton pattern, especially as it is often misused. Moving a code base from it often depends on how much refactoring you are ready to use. Singletones are similar to global variables: convenient, but not oily. Hmm, I think Iāll put this in my quotes file, it will be a nice phrase with it ...
Honestly, you know more about the code base and the application in question, and then about someone here. Therefore, no one can design it, and the tips say less than the action, at least where I come from.