I am in the center, trying to teach myself programming. I started the same way as most people. making small, dirty apps and games that make simple things not so easy. I recently tried to take the next step by writing a slightly more complex game that uses OOP design to write better, more modular code!
The main problem I ran into is the design of my main StateManager (FSM) class (for switching between I / O / menu / game / etc / states). I looked high and low, and I really saw two methods for designing them:
Now, my problem is that the case switch statement is very repetitive and clumsy, and this works against my goal of using this project to teach myself OOP.
My second and biggest problem is the "singleton" sentence.
As I said, I try to teach myself, and I still have a lot to learn when it comes to programming, especially in the area of OOP and design patterns and all that. I ran into a problem when for EVERY single “singleton” is an evil thread and discussion that I find, I find as many tutorials and links where people use single code in their code to create “motor” classes and FSM. This is a very consistent mixed message.
I suppose I just don’t understand why ... Even if you want / want to have only one class object, why is it necessary / useful to make the constructor private and create a singleton? I read a lot about how singles are bad, how they are essentially global, how they interfere with multithreading, and how many programmers consider them excessive or just bad projects ... But I see an example after the example of people using them, and very few examples examples showing alternative methods.
Is it possible to do the same with a regular class? What is the purpose of explicitly restricting instantiation? I only heard about negative things about singles, but people seem to use them all the time ... Am I missing something about singles and OOP?
Is singletons just a trend, or is it just a trend when people call loneliness? How do I get around this? Is there something between the FSM switch / foot and the singleton FSM ?? Could someone create their own state system of programs in the same way, without making any of their classes in single games? Will this change anything? [confused]
c ++ design oop singleton fsm
MrKatSwordfish
source share