Implementing Observer Pattern with C # MVC

Simple concept. This is for homework, we are encouraged to use ASP.NET to create an application using a database. I am planning to create a TTT (tick-tac-toe) web page where users can create games, join each other and write W / L records to the database. This will be using MVC.

I've worked with MVC before and I find it more convenient to create an application. I have a question about implementing the Observer pattern , so each user has the most recent copy of the game on their screen (view).

I am currently looking into ways to approach this. I can always make a Javascript function in the view that asks for the most recent copy of the game from the server every x seconds, so that both players always have an updated copy of the game. This will actually solve the problem, but will not implement the Observer pattern correctly. Which would be ideal if the views subscribed to the model, if the model ever changed (via a controller action), the model could send the update via the controller to the views. This second approach sounds a little odd, and I don't want to try it unless it suits the Observer pattern implementation.

What is the correct approach to implement the Observer pattern? If you've used it before, how did you do it?

+4


source to share


1 answer


Don't copy this and I will not condone cheating if you do.

But here is a decent example of what I think you are trying to do.



https://github.com/fekberg/Tic-Tac-Toe

+1


source







All Articles