|
|
|
|
|
by wsc981
5040 days ago
|
|
Just yesterday used a singleton in Objective-C due to a webservice that worked with a challenge-response system. Whenever I perform a request, I receive a code. The code is required in the next request to retrieve the data. The issue I was having, was sending lots of requests in different threads; this could cause a code retrieved in a previous request to become invalid, making an older request for data fail. I figured that by creating a singleton class responsible for executing requests sequentially, this problem would be fixed (and it did). This singleton class internally uses a FIFO-queue to execute all requests sequentially. I think it was an appropriate solution, especially since this singleton class is used internally, not exposed through interfaces to other classes interacting with my 'framework'. |
|
I was just curious about what 'singleton method' meant, as opposed to 'singleton object'. Sadly, it seems that it would be very hard to implement something similar in Python (my main language at the moment) without creating a metaclass. But I certainly saw this pattern in Smalltalk before, just didn't know how it's called.