As John mentioned, your first bullet point is right on.
Sometimes a Close()
method is functionally synonymous with Dispose()
, and exists to maintain semantic consistency with an abstraction. That is, to complement a Open()
method. Other times, Close()
will allow you to re-open, but Dispose()
should not. Your second bullet-point is therefore fine, as well.
Bullet point 3 is not necessarily applicable, because a disposed object should not be reused. If you need to call Open()
again, you need to use a new instance. In fact, the Open()
method should throw an ObjectDisposedException
once Dispose()
have been called (by checking a private disposed
boolean flag). If you want the object to support re-opening after close, you might consider using Debug.Assert()
and/or throwing an exception if Open()
is called without Close()
. This will help to prevent sloppy management of these instances.
Be sure to follow the full disposable pattern, which is more involved than simply implementing the interface:
bool disposed;
public void Dispose() // don't make virtual!
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if(!disposed)
{
if(disposing)
{
// dispose of managed resources here, for example:
// if(resource != null) { resource.Dispose(); }
}
}
// dispose of unmanaged resources here
disposed = true;
}