2011-02-08

Howto design a webapp C++ MVC API part 2

Doing a MVC implementation that is intuitive in C++ isn't very easy. I'm thinking about how to implement the controllers. Should the controller-class be inherited by the implementations or should it provide some kind of callback/signal-system. For some reason I seem to be against inheriting from the controller, but compared to a signal/slot or similar callbacksystem, this is probably the best and most intuitive option.

So I'm thinking something like this:
-----
// Create a webapp
forumApp myforum;
http_server.add_webapp("forum",myforum); // add the forumApp to the "/forum/"-path
-----
// Looking at the forumApp-class, it inherits the webapp_controller
class forumApp : public webapp_controller{


    // Set up the "sub" controllers in a static method
    static void add_controllers(dispatcher::ptr dispatcher){
        // Add the controller "forumAdministration" to the subpath "/forum/admin/"
        dispatcher->add_controller<forumAdministration>("admin"); 
        // Add the controller "forumThread" to the subpath "/forum/thread/"
        dispatcher->add_controller<forumThread>("thread");
        // Also add actions related to this controller 
        dispatcher->add_action(&forumApp::about,"about");
     }

     void about(connection &con){
         con.send_response("this is the best forumapp ever");
     }
}
-------
So, this is just initial thoughts. Writing about this helps me figure out how code would look like, and who knows, maybe I can catch someones attention.

Next up is how views should work and what type if template-system to use or not to use.

0 comments:

Post a Comment