Re: [PEPr] Comment on Tools and Utilities::ScriptReorganizer
| From: | Vincent Lascaux | Date: | Thu, 19 May 2005 11:05:35 +0000 |
| Subject: | Re: [PEPr] Comment on Tools and Utilities::ScriptReorganizer | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37753@lists.php.net to get a copy of this message | ||
> A decorator lets you change the skin of an object; a strategy lets you
> change
> the guts.
Hum... RenameVariables seems to change as much the "guts" of the code than
Pack...
> The strategies Pack, Quiet and Route are just different variation of the
> same core
> responsibility - the mandatory behavior as I have defined it (reduction of
> the file's
> size).
As I see it, RenameVariable achieve the same goal by giving shorter names to
the variables
> The decorators AddHeader, AddFooter and Pharize are responsibilities that
> can
> be withdrawn without affecting the object (and its responsibility) in
> discussion.
The Pack strategy (remove the unnecessary whitespaces) could be seen as a
decorator that can be withdrawn or not...
> ANN: That's the reason why I see RenameVariables as a decorator and not as
> a
> strategy. Depending on how it would be implemented as well as how the
> source to
> reorganize is structured, it could eventually even increase the files'
> size and thus not
> comply with the ScriptReorganizer's "contract".
I'm not sure we should define in a class is a subclass of another one by
looking at it's implementation. Do you also mean that decorators *HAVE* to
increase the size of the code? (Pharize may not respect this since the code
may be compressed).
I still can't see why changing the indenting of the code and changing the
variable names can't be seen as the same object... Rename variable seems to
me a valid strategy to reduce the code size, and addHeader / addFooters seem
to me valid strategies to "reorganize the script". It would even be really
easy to write a addHeader decorator:
class ScriptReorganizer_Strategy_AddHeader implements
ScriptReorganizer_Strategy
{
var $inner;
var $header;
public __construct($header, ScriptReorganizer_Strategy $inner = null)
{
$this->header = $header;
$this->inner = $inner;
}
public function reformat(& $content)
{
if ($inner != null) {
$inner->reformat($content);
}
$content = $header . $content;
}
}
It looks easier to understand, quite similar to the code of other
strategies... and more coherent to me.
--
Vincent