[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pear-dev
Subject:    Re: [PEAR-DEV] oo design question - how to avoid a factory
From:       Stefan Ohrmann <bshell () gmx ! net>
Date:       2004-12-22 22:38:21
Message-ID: 41C9F75D.9040706 () gmx ! net
[Download RAW message or body]

Hello,

Am 22.12.2004 19:19 schrieb Olivier Guilyardi:

> Stefan Ohrmann wrote:
>  > Then you also have to erase the
>  > Structures_DataGrid_Renderer:_parseHttpRequest() function, or it is used
>  > by every renderer?
> 
> It may be used by a variety of renderer, for example : Smarty, XUL ...

Then the various renderer should implement this function, when needed.
To me the whole design seems al little bit borked. Why is this
intermediate step Structures_DataGrid_Renderer between
Structures_DataGrid_Core and Structures_DataGrid, when
Structures_DataGrid does nothing elsa than calling it's parent. I think
Structures_DataGrid_Renderer should be merged with Structures_DataGrid.

Structures_DataGrid_Renderer should be used as an abstract superclass
for all renderers. This would helpful for all users who want to create
their own renderer. But their no way in using an own renderer, that lies
in way you implemented the setRenderer() function. It accepts
unfortunatly only a string as argument and looks in a harcoded directory
for the class of the renderer, if you modify my suggested version in the
following way:

    function setRenderer(&$renderer)
    {
	if (is_a($renderer, 'Structures_DataGrid_Renderer')) {
	    $this->renderer =& $renderer;
	    return true;
        }

        $class = 'Structures_DataGrid_Renderer_' . $renderer;
        $file = 'Structures/DataGrid/Renderer/' . $renderer . '.php';

        if (
            @include_once($file)
            && class_exists($class)
        ) {
            $this->rendererClass = $class;
        } else {
            $this->rendererClass = null;
            return new PEAR_Error('Invalid renderer');
        }

        return true;
    }

You also have to modify the renderer creation function:

    function _createRenderer()
    {
        if (
            isset($this->renderer)
            && is_a($this->renderer, 'Structures_DataGrid_Renderer')
        ) {
            return true;
        };

        $this->renderer = new $this->rendererClass($this);
        return true;
    }

regards

Stefan

-- 
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic