KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How can I determine if I should extend one of my interfaces with IDisposable or implement IDisposable on a class that implements my interface? I have an interface that does not need to dispose of any external resources, except for one particular implementation. My options seem to be: 1) Implement IDisposable on the interface requiring all of the implementations to implement Dispose, even if only an empty method. -or- 2) Implement IDisposable on only the classes that have resources needing to be disposed. This will cause problems with "using" because my object is created from a factory and therefore all upstream code works against the interface. Since the interface is not bound to IDisposable, "using" does not see the Dispose method. However, I could cast the factory result to the implementation; however, that then makes the consumer aware of the implementation, defeating the purpose of interfaces. Any ideas as to best practices?
Tags (comma-separated)
Save Edits
Cancel