Questions tagged [monostate]
13 questions
17
votes
5 answers
Class with static members vs singleton
Isn’t a class with only static members a kind of singleton design pattern? Is there any disadvantage of having such a class? A detailed explanation would help.

Shree
- 4,627
- 6
- 37
- 49
11
votes
1 answer
What should I use instead of void as one of the alternative types in an variant?
I want to have a variant which may contain type Foo, (disjoint) type Bar, or nothing. Well, naturally, I was thinking of using std::variant - but this doesn't seem to work. That is, you can define this type, but if you try to…

einpoklum
- 118,144
- 57
- 340
- 684
7
votes
1 answer
Singleton vs. Monostate Pattern in Ruby
Suppose a class needs to load an external library which takes some time to load and thus should be loaded only once. Two natural solutions to this would be to use the singleton pattern or the monostate pattern. Is there any advantage to either of…

user2398029
- 6,699
- 8
- 48
- 80
5
votes
2 answers
Python Deprecation Warnings with Monostate __new__ -- Can someone explain why?
I have a basic Monostate with Python 2.6.
class Borg(object):
__shared_state = {}
def __new__(cls, *args, **kwargs):
self = object.__new__(cls, *args, **kwargs)
self.__dict__ = cls.__shared_state
return self
def…

rh0dium
- 6,811
- 4
- 46
- 79
3
votes
3 answers
Class vs Instance Scope in JavaScript
I am evaluating a way of use the Singleton Pattern called Monostate in JavaScript.
I have some code like the following:
class Boss {
get name() { return Boss._name }
set name(value) {
Boss._name = value;
}
get age() { return Boss._age…

Ruben Saucedo
- 239
- 1
- 13
2
votes
2 answers
How to prevent a C++ compiler from creating any default class member?
I'm designing some classes to access and control the peripherals of a microcontroller (adc, port, usart etc). The device have just a few (in some cases just one) instances of each peripheral, so I decided to represent each peripheral as a monostate…
user4546925
2
votes
1 answer
Polymer monostate pattern element not upgraded
I'm having issues with the monostate pattern in Firefox 35, using Polymer 0.5.2. My element looks like this: