I had no real problems with the challenge like veganjay, but do have a question about the “right” way to structure which classes perform the actual delete and how once it is selected by the user.
Crime offers setPhoto and getPhoto methods. veganjay and I in my first solution that works put all the file deletion logic in CrimeFragment - this includes the file deletion activity, invoking setPhoto(null) to remove the Photo from the Crime.
However I think from an OOP perspective numerous things are “wrong” here and need advise on the “best practice” approach re:OOP.
The Photo object which was created when the picture was created which contains the filename is not deleted at all. There is no “delete” or destructor for the Photo class and so the memory consumed by the Photo object is never freed.
Generally I also think the code that performs the deletion of the file in storage and the code that should remove the Photo object should be in the Photo and/or Crime classes. One could implement Crime.deletePhoto() and do all the legwork there including setting Crime.mPhoto=null, invoking a Photo destructor, and freeing up the file storage.
OR one could actually do the removal of the file on disk in a destructor/delete method of the Photo class which would be invoked by Crime.deletePhoto or Crime.setPhoto§ when Crime.mCrime != null on a setPhoto invokation.
So my questions are:
- Which flavor of the above is “right” according to the lore of OOP? Shouldn’t the file handling be abstracted to the Crime at least?
- How would one go about deleting the Photo object? Or should I just not worry about this since the last reference to it is set to null in Crime and thus it becomes eligible for garbage collection? The only references to the Photo object are the local object used when it was created when the photo was taken which should disappear when the local frame exits, and the one internal to Crime which persists.
Thanks in advance.