Problem with overriding Functions (oop)

Hi,

i'va got a class 'Page'. One of it members is an instance of a template engine.
The Page-class has a method render() which calls the functions read(),
transform(), transport() and starts the template engine.

Now I want to reuse the Page class for a more specialized page 'ImagePage'. So:
ImagePage extends Page. This Page contains an extra picture and therefore needs
to call image() before starting the template engine. How do i smartly integrate
that call into the Page::render() function.

I could override the whole funtion, but then i'd have to copy and paste the
whole code for the calls of read(), transform(), transport()?
What's the professional way here?

Johannes
Johannes Permoser [ So, 20 Januar 2008 00:32 ] [ ID #1912516 ]

Re: Problem with overriding Functions (oop)

On Sun, 20 Jan 2008 00:32:16 +0100, Johannes Permoser <ee_pp [at] yahoo.de>
wrote:

> Hi,
>
> i'va got a class 'Page'. One of it members is an instance of a template
> engine. The Page-class has a method render() which calls the functions
> read(), transform(), transport() and starts the template engine.
>
> Now I want to reuse the Page class for a more specialized page
> 'ImagePage'. So: ImagePage extends Page. This Page contains an extra
> picture and therefore needs to call image() before starting the template
> engine. How do i smartly integrate that call into the Page::render()
> function.
>
> I could override the whole funtion, but then i'd have to copy and paste
> the whole code for the calls of read(), transform(), transport()?
> What's the professional way here?


class ImagePage extends Page{
function render($arg){
$this->image();
parent::render($arg);
}
}

--
Rik Wasmus
luiheidsgoeroe [ So, 20 Januar 2008 00:39 ] [ ID #1912518 ]
PHP » comp.lang.php » Problem with overriding Functions (oop)

Vorheriges Thema: PHP equivalent to Perl's !~
Nächstes Thema: Re: HTML Purifier