Singleton: Difference between revisions
Content added Content deleted
(→{{header|Java}}: Add Enum as a singleton) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
Line 2,337: | Line 2,337: | ||
In practice, it's unlikely anyone would bother; they'd just create a class with static methods and/or fields only which is effectively a singleton as there's only ever a single instance of a static field. |
In practice, it's unlikely anyone would bother; they'd just create a class with static methods and/or fields only which is effectively a singleton as there's only ever a single instance of a static field. |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">class Singleton { |
||
// Returns the singleton. If it hasn't been created, creates it first. |
// Returns the singleton. If it hasn't been created, creates it first. |
||
static instance { __instance == null ? __instance = Singleton.new_() : __instance } |
static instance { __instance == null ? __instance = Singleton.new_() : __instance } |