Re: creating new class from wrapper class (OOP question)
| From: | David Hall | Date: | Thu, 19 Jan 2006 18:14:17 +0000 |
| Subject: | Re: creating new class from wrapper class (OOP question) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-228843@lists.php.net to get a copy of this message | ||
Henrik Gemal wrote:
In a image gallery I have to class'es: class GPicFilePicture extends GPicFileType class GPicFileMovie extends GPicFileType both of them are based on: abstract class GPicFileType In my code I need to create a new GPicFilePicture. To avoid duplicated code I've create a wrapper class: class GPicFile that does something like this: if (fileextension == "jpg") return new GPicFilePicture(); else return new GPicFileMovie(); so my PHP code looks like: $file = new GPicFile($filename); getFileDate() is implemented in both GPicFilePicture and GPicFileMovie. Now I try to do: $file->getFileDate(); I get an error saying: Call to undefined method GPicFile::getFileDate() Where am I going wrong?My way for doing this summed up by the Factory Pattern described on this page: http://www.phptr.com/articles/article.asp?p=346958&seqNum=4