Closed Bechir-Brahem closed 7 months ago
Sorry I commented on the other PR first. Didn't realize that you it was based on this. My main question is what is the benefit of the contextManager compared to handle it on a file by file basis.
class File{
FileInterface* m_fileptr;
public:
File(filenam){/*open file*/}
~File(){{/*close file*/}
}
int main(){
File f("/some/file.name", "r");
// do stuff with the file
// once the files goes out of scope it's closed
}
that's what I meant with the FileWrapper. The problem with it is that we will have to implement the FileInterface in it and whenever we change the interface we will have to change in the File wrapper.
squash merge of PR #26
if we are using derived classes (JsonFileFactory->FileFactory, JsonFile-> File) and we want to abstract the user's code from different types of File classes then there's no escape from returning a pointer or reference to class File. doesn't seem like we can use RAII because File is abstract, and if we make it not abstract then the right destructor won't be called
This PR introduced the class ContextManager to handle opened resources such as network connections or opened files
other solutions that can also be done:
FileWrapper that takes File* and destroys it when out of scope,