Singleton: Difference between revisions
Content added Content deleted
m (→Thread-safe) |
(→{{header|Vala}}: Singleton!) |
||
Line 1,438: | Line 1,438: | ||
% $b counter |
% $b counter |
||
4</lang> |
4</lang> |
||
=={{header|Vala}}== |
|||
<lang Vala>public class Singleton : Object { |
|||
static Singleton? instance; |
|||
// Private constructor |
|||
Singleton() { |
|||
} |
|||
// Public constructor |
|||
public static Singleton get_instance() { |
|||
if (instance == null) { |
|||
instance = new Singleton(); |
|||
} |
|||
return instance; |
|||
} |
|||
} |
|||
void main() { |
|||
Singleton a = Singleton.get_instance(); |
|||
Singleton b = Singleton.get_instance(); |
|||
if (a == b) { |
|||
print("Equal.\n"); |
|||
} |
|||
}</lang> |
|||
{{omit from|AWK}} |
{{omit from|AWK}} |