stefan8893 / simple-trading

MIT License
1 stars 0 forks source link

TestData builder should not create new instances when accessing the Default property #5

Closed stefan8893 closed 3 months ago

stefan8893 commented 3 months ago

In order to satisfy the interface 'ITestData<TEntity, TTestData> derivatives have to:

...

public static Asset Default => new();

...

But creating a new instance every time is useless.

Solution: Create a static backing field that holds the immutable default value and accessing the property only returns the backing field. Optional use a singleton to defer its creation.