views:

380

answers:

3

I find that writing web apps and WinForm apps generally come out a lot cleaner than when I write a console application.

What do I mean by cleaner? Well the fact that the fact the UI (i.e. readline/writeline) is so intertwined with the logic code becomes horrible and the fact it is not event driven means that it is harder to get good abstraction.

I was thinking about this and MVC does try to solve similar issues for web apps, so my question is there anything like that for console apps? or any guides to get better design into console apps?

A: 

Model View Control is a design pattern and as such is applicable to both Web Apps and console apps. Perhaps you should ask the question How do you apply MVC to your console app.

Regards

Howard May
A: 

I think you can still use MVC for console apps.

Remember that in web apps and WinForms, a lot of interaction is abstracted away from you, but is still present in the view logic, e.g. what elements to show when a tab is clicked.

That is the kind of interaction that you have to code yourself in a console app, but there's no reason that that couldn't be done entirely in the code for the view.

My take on MVC is that the view is entirely responsible for displaying the right data, options, etc.. In that light, it's not a crime to have logic in the view, as long as that logic is only related to how stuff is displayed.

Of course, splitting the view into different classes will probably make things a bit easier (for example, you could split the view code itself into an MVC pattern, although that can become complicated really quickly with entities like IAppView, IAppViewController, IAppViewView, you get the point :) ).

Lennaert
+5  A: 

I think you'll find that the a popular alternative to Model View Controller is Model-View-Presenter. The model is basically the same between the two. The role of the controller and view are very similar, but they may get a little more responsibility depending upon your implementation. Within MVP, there are two implementation methods: Supervising Controller and Passive View. MVP is usually considered the standard architecture for WinForms clients and can be applied to WebForms as well. Here are some relevant links for more information:

Finally, if you want to pick up a book, Agile Principles, Patterns, and Practices in C# contains an excellent walkthrough for building a console-based payroll application. Once compeleted, they build to WinForms UI to show how their application architecture allowed them to add a new view with minimal fuss.

Brad Gignac
I apologize for the lack of actual hyperlinks, but I'm a new user and am capped on the number that I can post.
Brad Gignac
@Brad, welcome to StackOverflow! I added the hyperlinks to your post.
Dennis Palmer