vigge Posted November 21, 2007 Share Posted November 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 I would think you would want the pFile class to simply be a factory that returns the appropriate object. Quote Link to comment Share on other sites More sharing options...
vigge Posted November 21, 2007 Author Share Posted November 21, 2007 Alright, that's what I'll do then - thanks . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.