2 ms·
> Like what? Seriously? Do you have any evidence to backup the assertion of design techniques that are appropriate for some situations but not others? It's har
by mikekchar 10y ago
> Like what? Seriously? Do you have any evidence to backup the assertion of design techniques that are appropriate for some situations but not others?
It's hard to say what you mean by this. I have difficulty believing that you think that a technique used in one situation is always going to be the best technique to use.
As someone has already graciously described situations where Flyweight can be used, perhaps something simpler than that like the Singleton can be illustrative.
The OP opined that the Singleton is only useful to people who don't know how to use a global variable. If that were the case, it would not be useful at all. In fact, it's usually something to stay away from. However, it absolutely shines when you want to make sure that an entity's constructor is only called exactly once.
There are many situations where you need to do this -- often when interacting with hardware, this kind of thing is crucial. As the OP suggested, though, it's easy to misuse this pattern.