"This is the delegation pattern, we use it to _________" "This is a singleton method, it's best used for ____"
"Create an MVC structure using the strategies we discussed"
"This is the delegation pattern, we use it to _________" "This is a singleton method, it's best used for ____"
"Create an MVC structure using the strategies we discussed"
The problem is that until you're faced with a real-world software system with real-world problems - and in particular, faced with the consequences of your misuse - you'll be tempted to use them in places where they're not the best solution. It's one thing to read something in a textbook. It's another thing to wrestle with a million-line codebase and try to make sense of it.
Singletons, for instance, almost always turn out to be an antipattern in the long run. You're better off injecting your dependencies explicitly, even if you only think there is one in the whole program. Delegation is used all the time, but can also be overused, and it's important to know when you're better off modifying the original class rather than trying to wrap it with something else.
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.
static MySingleton *sharedSingleton;
+ (void)initialize { static BOOL initialized = NO; if(!initialized) { initialized = YES; sharedSingleton = [[MySingleton alloc] init]; } }