C# Design Patterns – How to Design Console Application with Good Separation of UI from Logic

cdesigndesign-patternsmvcmvp

  1. Is it considered an overkill for console application to be design like MVC , MVP or N tier architecture? If not which is more common and if you can link me to simple example of it.

  2. I want to implement a tic tac toe game in console application.
    I have a solution which hold two projects: TicTacToeBusinessLogic (Class library project) and
    TicTacToeConsoleApplication (Console application project) to represent the view logic.
    In the TicTacToeConsoleApplication I've Program.cs class which holds the main entry point (public static void Main).
    Now I face a problem.
    I want the game to handle its own game flow so I can:
    Create new GameManager class (from BL) but this causing the view to directly know the BL part.

So I'm a little confused how to write it in an acceptable way.
Should I use delegates? Please show me a simple example.

Best Answer

I would at the very least go with something where you have one layer that listens to keyboard etc. events and translates those into calls into the game logic layer and gets updated (Observer) as those calls change the state of the game.

Take it a few steps further and guess what, you are back in MVC or MVP or MVVM territory.

Whether or not to go with any of these patterns has nothing to do with the type of UI, and everything to do with separation of concerns, loose coupling and maintainability.