Hi!
i have always wondered how to handle Files in applications. Say we have an Object containing several data about a File like a UUID and the reference to the file on disk.
Even if this Object is immutable, there might be side effects like the file will be deleted by a part of the application but the other do not know about it, rendering the Object unusable.
Is there a handy pattern I can use for such cases? Or do I have to double-check every time I use the Object that the File reference actually points to an existing file? This might be the only solution since the file can be deleted from outside of the application, but may leave the application in hard-to-handle situation.
The problem exists the other way around: Who is responsible for deletion of the file? Since the Object might be an ordinary value object it may be referenced by other parts of the system no part of the code can delete the file for cleanup propourses to avoid side-effects...
But there might be a pattern or policy that can be used to ease the handling in such cases.