views:

68

answers:

2

I have multiple Controller objects that either execute some script and then redirect to a specific page, or gather some data, send it to a View object and then display that View.

Instead of having a page for each controller instantiation (for example main_menu.php, image_browser.php, manage_users.php), I have an index.php page that contains a class which instantiates specified classes. The class to be instantiated is specified via URL GET variables when index.php is called. The class that manages instantiation checks if the specified class is in an array of allowable class names and, if it is, it instantiates the class (controller) and if it is not, it instantiates the MainMenu class.

Is this class that I have, which manages legal class names, a design pattern?

Or, is this not a design pattern?

+1  A: 

I'd say it's the dispatcher pattern with access control. Usually, though, having directly user-specified flow-of-control in a web application an anti-pattern.

Borealid
@Borealid - Would you please explain more about what you mean by user-specified flow-of-control?
letseatfood
@letseatfood: If which class is instantiated is controlled directly by the user, then the user specifies the flow of control of your application. This is an easy way to open yourself up to security issues if you're not very careful with controlling access.
Borealid
+3  A: 

Sounds like a FrontController to me:

The Front Controller consolidates all request handling by channeling requests through a single handler object. This object can carry out common behavior, which can be modified at runtime with decorators. The handler then dispatches to command objects for behavior particular to a request.

See also:

Gordon
@Gordon, I didn't know about the Front Controller. I think my setup is actually a Page Controller (or bastard wannabe), but I didn't know about Page Controller until you shared Front Controller. Thank-you!
letseatfood
@letseatfood you're welcome. IMO, you can have both. Many Page Controllers that handle input, delegation to model and View render dispatching. And a FrontController that serves as a central access point to these controllers and does setup things needed in all PageControllers. FrontController is a common pattern to go with MVC.
Gordon