J
Julie
(I searched the FAQ, but didn't find anything relevant -- if there is, please
post a link.)
Is there a design paradigm that indicates that a class that manages an external
resource should automatically perform clean up in the destructor?
For example, suppose the following file-wrapper class.
// begin
class file
{
private:
int fileHandle;
public:
file()
{
fileHandle = 0;
}
void open(char * fileName)
{
fileHandle = MySystemIO::OpenFile(fileName);
}
void close()
{
if (fileHandle)
{
MySystemIO::CloseFile(fileHandle);
fileHandle = 0;
}
}
~file()
{
// call close() here or not?
// close();
}
}
// end
I realize that from a /documentation/ standpoint, I can do either and just
document wether or not the destructor performs cleanup
-- however --
I'm mostly interested in a self-documenting code perspective, where (external)
documentation isn't referenced.
Comments???
post a link.)
Is there a design paradigm that indicates that a class that manages an external
resource should automatically perform clean up in the destructor?
For example, suppose the following file-wrapper class.
// begin
class file
{
private:
int fileHandle;
public:
file()
{
fileHandle = 0;
}
void open(char * fileName)
{
fileHandle = MySystemIO::OpenFile(fileName);
}
void close()
{
if (fileHandle)
{
MySystemIO::CloseFile(fileHandle);
fileHandle = 0;
}
}
~file()
{
// call close() here or not?
// close();
}
}
// end
I realize that from a /documentation/ standpoint, I can do either and just
document wether or not the destructor performs cleanup
-- however --
I'm mostly interested in a self-documenting code perspective, where (external)
documentation isn't referenced.
Comments???