Skip to content

Instantly share code, notes, and snippets.

@heftekharm
Last active November 25, 2021 15:26
Show Gist options
  • Save heftekharm/1f9438136fdb48a73a695d1615431de9 to your computer and use it in GitHub Desktop.
Save heftekharm/1f9438136fdb48a73a695d1615431de9 to your computer and use it in GitHub Desktop.
final _alreadyCreatedCircleInstances = Map<int, Circle>();
class Circle {
final int size;
Circle._(this.size);
factory Circle(int size) {
_alreadyCreatedCircleInstances[size] = _alreadyCreatedCircleInstances[size] ?? Circle._(size);
return _alreadyCreatedCircleInstances[size]!;
}
}
void main(){
var c1 = Circle(40);
var c2 = Circle(40);
print("${c1 == c2}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment