13Aug Self Instancing Singletons
303 views
While working on a class recently, I have discovered an interesting design pattern where a singleton class is able to create instances of itself to perform RPC actions. For example, you could create a singleton called
LoadAndPlaySound.gi.play(
url:String,
onLoad:Function,
onSoundPlayed:Function)
This class would then be able to create an instance of itself for handing the loading process for the sound, any manipulation, or other processes like handing storing and executing callback variables. You will need to lock down the singleton using a kind of enforcer technique so that only the singleton can replicate itself.
Disclaimer: I general do discourage singletons though as if used improperly (like stuffing every variable in an application into it for the point of easy access), it can cause more headaches than they relieve.
Auto-Generated Related Posts:
