The Model-View-Controller architecture
Woof! is based on the View-Controller components of the well known Model-View-Controller (MVC) architecture. A Google search on MVC web frameworks will turn up more than enough information for those who are not familiar with it so here we only present a (very) short summary.
In the MVC architecture, the application is divided into three components:
- the model encapsulates the application data and logic that transforms the data while enforcing associated rules. For example, in a banking application, application data would include account balances, the transforms would include methods to debit accounts, and the rules would prevent overdrafts beyond a limit.
- the view implements presentation of that data, possibly in multiple forms. Examples of views in the banking application are account balance summaries and transaction histories.
- the controller, as the name suggests, contains the application logic that coordinates the whole process of interaction with the user, applying the desired transforms to the model, and invoking the appropriate views.
Naturally, there can be multiple instances of each of these components within an application.
Woof! currently provides the view and controller components of the MVC architecture. It is not clear that model component belongs to a Web framework although most other frameworks do include that component as well.
When a client request is received, its URL is mapped to an appropriate controller class. An instance of the controller is created to handle the request. The URL mapping also specifies an action (method in the class) to be executed by the controller. This action corresponds to a user request such as a transform to be applied to the model or generation of a different view. The controller class invokes the specified action method passing in any extracted parameters from the query. The action method then in turn invokes one or more methods on the model component.
The view component is a template corresponding to the controller and action that is processed to generate a Web page sent back as a response to the client. The template is a combination of static HTML layout and text with placeholders for dynamic data. The web page is generated by filling in these placeholders with the data provided by the model through the controller class.
The basic idea is straighforward, the key point being the clear separation of the presentation from the application logic.