3 ms·
In the spirit of correcting people, a singleton is absolutely an OO pattern, which doesn't mean it can't also be a "memory access pattern" (in some sick twisted
by stagger87 6y ago
In the spirit of correcting people, a singleton is absolutely an OO pattern, which doesn't mean it can't also be a "memory access pattern" (in some sick twisted meaning of memory access pattern). I mean, it was brought to fame by the GoF OO design book.
- rumanator 6y agoNo, a singleton is not a OO pattern. At all. Quoting GoF does nothing to refute that fact. A singleton is just a way to ensure a single object is instantiated and exists system-wide. That's it. It's a global object, attached to a negligible (and thus often ignored) requirement to not allow instantiating other objects of the same type. One way to implement singletons is to get a static function return a static variable. No OO required. It's all about memory access. Single variable used to store global state. That's it.
- stagger87 6y agoI appreciate your response. Unfortunately, I don't feel you have presented a convincing argument against its established classification as an OO design pattern for the last several decades. Additionally, "memory access pattern" does have an established definition (which you may also be opposed to), and you may confuse people with your usage of it. https://en.wikipedia.org/wiki/Memory_access_pattern https://en.wikipedia.org/wiki/Memory_access_pattern
- rumanator 6y ago> I appreciate your response. Unfortunately, I don't feel you have presented a convincing argument against its established classification as an OO design pattern for the last several decades. The argument is self-evident. A singleton does not use or need any OO construct to be implemented or used. There is nothing special or specific to OO to exclusively own the concept of ensuring a single globally-accessible system-wide data structure. As I've said, singletons are implemented with static functions returning static variables. No OO involved at all. Your only argument tying singletons to OO is the fact they are covered in GoF. However, that argument has no merit not makes any sense. GoF does not specify what is and is not OO. It only shows basic design patterns and presents ways of implementing them with OO languages. Otherwise you would also claim that instantiating variables is OO just because GoF describes factory methods.