Want to impro开发者_如何学Gove this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this questionCan / Should MVC be used on a SVN or HG type CLI application? If so, how might one go about this?
I've been trying to come up with a design and I've come to the conclusion that MVC and HG/SVN type interface simply doesn't work together; that they serve separate purposes.
Just to be clear, what I mean by the Hg/SVN type interface is issue a command to run the program, it runs and terminates:
hg commit -m"my message"
or
svn up
What is HTTP? You send a command up to the server. That command is "get me page X".
What is CLI? You send a command to the server. That command is "show me thing Y".
So at the core level, the concepts are very similar: you send a command; the "server" interprets that command against some kind of "model". Then, it morphs the model using some sort of logic (controller) and presents it to you (view).
Unless your CLI application is very simplistic, I'm assuming it has some sort of state. For example, you can go into screen A, and pick a record A1 from the list {A1, A2, A3}. Those records probably come from a database or some flat file.
What would this mean in a Web application? You navigate to a page; the page is shown to you based on some model (there's one class that helps you interact with the database and get a list of records). It's then transformed into HTML by some controller. It's then styled in your view (HTML < table >).
What would it mean in a CLI application? Exactly same thing. Except that your "view" is going to be drastically more simplistic (instead of a separate fancy HTML template file, you'd probably have a sprintf()-type deal)
精彩评论