Files
Aer/tests/singleton_test.aer
T

39 lines
682 B
Plaintext

import 'console';
final class Test {
private int $value;
private void __construct() {
Console::Print('Constructor called.' + "\n");
}
private void __destruct() {
Console::Print('Destructor called.' + "\n");
}
/* This is singleton */
public static object getInstance() {
static object $instance;
if(!$instance) {
$instance = new Test();
}
return $instance;
}
public int get() {
return $this->value;
}
public void set(int $value = 0) {
$this->value = $value;
}
}
final class Program {
public void main() {
object $testA = Test::getInstance();
$testA->set(5);
object $testB = Test::getInstance();
var_dump($testB->get());
}
} /* class */