envied icon indicating copy to clipboard operation
envied copied to clipboard

refactor: Switch to singleton pattern in app_env.dart

Open flawnn opened this issue 1 year ago • 2 comments

Hey 👋

Little change that, I thought, is quite nice, especially regarding people who copy the example & use it straightaway.

The reasoning is that it is plain better, & more efficent to implement the Singleton pattern with the Dart Factories for the AppEnv than to create a new instance with each call to the constructor

flawnn avatar Aug 17 '24 07:08 flawnn

Is done! Sorry, something went wrong on my side there.

flawnn avatar Aug 18 '24 11:08 flawnn

How's this going ?

rapiddesigns avatar Oct 03 '24 23:10 rapiddesigns

Does this really make any difference? As far as I can see, there is always only a single instance that is being created since the field was always marked static final. The "constructor" (i.e., factory) just returns this instance that was created at some point - basically the same procedure as a singleton, just easier to read, less to write and exactly as efficient. Because of this, I actually prefer the old code.

ThexXTURBOXx avatar Nov 04 '24 14:11 ThexXTURBOXx

As far as I can see, there is always only a single instance that is being created since the field was always marked static final.

Fair point.

techouse avatar Nov 06 '24 22:11 techouse