1

I'm developing a C-based software in which I want to use a Model-View-Controller approach, and while I think I quite got into the style's rules, I don't really understand where should I place the methods about connecting to the server (I'm developing a client). One of the cool things of MVC is unlinking the actual logic of the program from the architecture of the machine and system you're working on, but every machine has different ways of managing connections, so I guess model isn't the best place for that. But controller and view should be about visualizing stuff and taking inputs from the user, so it's not really clear where should I put that.

Any advices?

  • The controller and model may both be on the server. Or all three on the client. The server connection is not part of anything MVC addresses; it is a separate concern. – Frank Hileman Jun 18 '17 at 22:17
1

A view is where you put logic that presents the state of what you are modeling.

A model is where you put logic that manages the state of what you are modeling.

A controller is where put logic that seeks to change the state of what you are modeling.

There can be many views and controllers for the same model. A view might talk to a GUI. It might talk to a server. A controller might get input from a GUI. It might get input from a server.

MVC is about focusing on three areas of responsibility. That doesn't mean you can only have three modules.

  • So is it a logical approach to separate some code in another "view" that talks to the server? Or would it be better, as my software uses quite a lot of system-specific code, libraries using it I've already put in a fourth module called "utils" in order to leave the model clean and portable C only, to include the network connection code in the utils module too? – Eärendil Baggins Jun 18 '17 at 19:01
  • @EärendilBaggins What is the server connection for? If it is to control the controller, it will be associated with that. If it is to serialize the model, it should be in a separate layer. – Frank Hileman Jun 18 '17 at 22:19
  • System specific code belongs in a module called after that system. Putting it in a module called "utils" is asking for it to get mixed in with functions that calculate the area of a circle and objects that do nothing more useful than say "hello world". Always use positive names to organize concepts. Never use names that mean not part of something like "not model", "auxiliary", "extra", "miscellaneous" or "utils". Don't use names that mean I have to guess what's inside. – candied_orange Jun 18 '17 at 22:22
  • @CandiedOrange Oh, nice advice. To be honest our utils folder is just a place where we put some utilities we developed which could be used later, but I guess your idea is better. – Eärendil Baggins Jun 19 '17 at 14:16
  • 1
    Sounds to me like a Service tier which use to be "below" the MVC tier. The MVC component in charge of the communication, IMO is the model. The same way the model access to the DB it can access to the server via servicies. – Laiv Jun 19 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.