You are here: Re: [PHP] creating new class from wrapper class (OOP question) « PHP « IT news, forums, messages
Re: [PHP] creating new class from wrapper class (OOP question)

Posted by Jochem Maas on 01/19/06 09:59

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();

I assume the above is in your constructor, and running php5.
if so then what your returning is not being returned... php is returning
the GPicFile object you just asked for instead.

try something like:

GPicFile
{
function __construct($f)
{
if (fileextension == "jpg")
$this->decoration = new GPicFilePicture();
else
$this->decoration = new GPicFileMovie();
}

function getFileDate()
{
$this->decoration->getFileDate()
}
}

which I believe is called a decorator pattern (don't quote me.)

>
> 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?
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация