1

I just learned about the MVC architecture. I was going back and working on a command line file transfer application I wrote, and I was curious, to what degree should command line interfaces follow the MVC pattern?

3

Model View Controller isn't just for applications with GUI's. Very simply it's the idea that you can separate your code into at least three areas of responsibility. Actually, under MVC the fact that your application is a CLI is a detail to which the model can be blissfully unaware. One of the advantages of this is that means you can use the same model untouched if you decide to make a GUI version of your App.

CLI or not, the "degree" to which you should follow MVC depends entirely on how much you care about writing code that welcomes a requirements change. Otherwise, feh, who cares?

  • Your second paragraph makes it sound like MVC is the only way to write flexible, maintainable software. That isn't true. – whatsisname Oct 13 '17 at 22:31
  • MVC is primarily about GUI (i.e. decoupling the View from the rest of the system), and since CLI doesn't have a GUI, well... – Robert Harvey Oct 13 '17 at 22:54
  • @RobertHarvey, I would say MVC is primarily about UI, which can take many forms, but graphical is certainly a very prevalent form. The View is all about presenting data to the user and that applies equally in a GUI and a CLI. – Bart van Ingen Schenau Oct 14 '17 at 7:57
  • @BartvanIngenSchenau: Agreed. MVC isn't particularly interesting from a CLI perspective, however. Your CLI might be one class, or perhaps a parser. – Robert Harvey Oct 14 '17 at 14:34

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.