S
Samuel R. Neff
I'd like some opinions on whether or not to use IDisposable for
classes that require clean-up but when the clean-up is not related to
unmanaged resources or other disposable objects.
The most descriptive case is unit test data. We have unit test data
classes that generate fake data in the database which we can then test
against, and then the unit test data classes delete those records.
We can have all of these test data classes implement IDisposable and
the Dispose method can clean up the data (not during garbage
collection of course..only when someone actually calls Dispose).
An alternative viewpoint that's been suggested is that this is an
abuse of IDisposable and we instead should just have a CleanUp method
or something similar that cleans stuff up and all developers have to
know to call CleanUp.
What are pro's and con's of each approach? Are there any established
standards of what not to use IDisposable for?
Thanks,
Sam
classes that require clean-up but when the clean-up is not related to
unmanaged resources or other disposable objects.
The most descriptive case is unit test data. We have unit test data
classes that generate fake data in the database which we can then test
against, and then the unit test data classes delete those records.
We can have all of these test data classes implement IDisposable and
the Dispose method can clean up the data (not during garbage
collection of course..only when someone actually calls Dispose).
An alternative viewpoint that's been suggested is that this is an
abuse of IDisposable and we instead should just have a CleanUp method
or something similar that cleans stuff up and all developers have to
know to call CleanUp.
What are pro's and con's of each approach? Are there any established
standards of what not to use IDisposable for?
Thanks,
Sam