Re: oo design question - how to avoid a factory

From: Date: Wed, 22 Dec 2004 22:38:21 +0000
Subject: Re: oo design question - how to avoid a factory
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35232@lists.php.net to get a copy of this message
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

« previous php.pear.dev (#35232) next »