CGI Development - Multiple Entry or Dispatch

Joshua Goodall joshua at roughtrade.net
Sun Nov 3 23:26:00 CST 2002


On Mon, Nov 04, 2002 at 10:01:07AM +1100, Scott Penrose wrote:
> dispatch.cgi
> ------------
> 
> 	use MyImplementation;
> 	my $m = MyImplementation-new();
> 
> 	if ($ENV{PATH_INFO} eq "") {
> 		$m->view;
> 	} elsif ($ENV{PATH_INFO} eq "edit") {
> 		$m->edit;
> 	} elsif ($ENV{PATH_INFO} eq "save") {
> 		$m->save;
> 	} else {
> 		$m->error;
> 	}

This seems more maintainable to me. You could even abstract it
(validation notwithstanding):

	use MyImplementation;
	use CGI;

	my $m = new MyImplementation;
	my $q = new CGI;
	my $p = $ENV{PATH_INFO};

	$m->$p($q) if $m->publicmethod($p);

This turns the request into a facade for invocation of a method
on a visited object.  OO pattern freaks please note :)

This is not unlike the container model of a J2EE server, although
without any of the sophistication (resource/instance pooling etc).

If MyImplementation is autosplit, then neither approach needs much
compilation.

The dispatch model also allows MyImplementation to be a completely
remote process.  In the multiple methods model, you're constrained
to only implementing remote methods known in advance.

Not many people need such separation, of course.  I think ultimately
only very large or complex OO systems benefit (in maintainability)
from strict pattern usage.  Everything else seems to fall into the
category of "whatever seems most appropriate at the time".

Joshua



More information about the Melbourne-pm mailing list