开发者

What design pattern is this? (Or, can you recommend a pattern for my specific problem?)

开发者 https://www.devze.com 2023-01-10 21:48 出处:网络
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.

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 patt开发者_StackOverflow中文版ern?

Or, is this not a design pattern?


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:

  • http://en.wikipedia.org/wiki/Front_Controller_pattern


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号