Last active
May 17, 2024 05:41
-
-
Save kariyayo/f67cfb7d1ac556c5e363594b730a076e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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