Front Controller pattern

From Wikipedia, the free encyclopedia

The Front Controller Pattern is a software design pattern listed in several pattern catalogs. The pattern relates to the design of web applications. It "provides a centralized entry point for handling requests."[1]

The front controller may manifest as a script in a script language like PHP, ASP or JSP that is called on every request of a web session. This script, for example an index.php, would handle all tasks that are common to the whole application or the framework around, like session handling, caching, input filtering. Depending on the given input it would then instantiate further objects and call methods to handle the particular task.

The alternative to a front controller would be individual scripts like login.php and order.php that would each include the code or objects that are common to all tasks. This would need a repetition of the inclusion code in each script but might also leave more room for specific needs of a script.

[edit] Examples

Several web-tier application frameworks implement the Front Controller pattern, among them:

[edit] Notes

  1. ^ Alur, Core J2EE Patterns, p. 166.

[edit] References

  • Alur, Deepak; John Crup, Dan Malks (2003). Core J2EE Patterns, Best Practices and Design Strategies, 2nd Ed.. Sun Microsystems Press, 650pp. ISBN 0-13-142246-4.