Skip to content

Instantly share code, notes, and snippets.

@kariyayo
Last active May 17, 2024 05:41
Show Gist options
  • Save kariyayo/f67cfb7d1ac556c5e363594b730a076e to your computer and use it in GitHub Desktop.
Save kariyayo/f67cfb7d1ac556c5e363594b730a076e to your computer and use it in GitHub Desktop.
class Color {
Color(this.name);
String name;
String toString() {
return 'Color:${this.name}';
}
}
class ColorHolder {
Color? _cache;
void create() {
if (_cache == null) {
_cache = Color("black");
} else {
_cache = Color("red");
}
}
Color? get() {
return _cache;
}
}
void main() {
final holder = ColorHolder();
final c1 = holder.get();
print(c1);
print('\n create \n');
holder.create();
final c2 = holder.get();
print('c1: $c1');
print('c2: $c2');
print('\n create \n');
holder.create();
print('c1: $c1');
print('c2: $c2');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment