I'm currently working class representations of some different filesystem objects. Currently I've got these pretty much done:
class pFileSystemObject {}
class pFolder extends pFileSystemObject {}
class pFile extends pFileSystemObject {}
class pImage extends pFile {}
Anyway, whenever an instance of the pFile class is created, I'm planning on having the constructor check what the extension for the passed file is and then convert itself into for example a pImage instance if the extension is jpg/gif/png/etc. Is this possible in some simple way or will I have to create a new pImage instance inside the pFile class, re-set all the attributes for it and then destroy the pFile instance?
Would I be doing this the wrong way? Should I check the extension before instancing the class and then create an instance of the appropiate one (I'm thinking this should be avoided since as much as the work of figuring out what type of file should be done inside the class itself)? Maybe using a Factory class would be the best choice?
I'm having trouble deciding this alone as I've just started with OOP, so any advice on this would be great.
Cheers