Coder Social home page Coder Social logo

mentalmove / mills Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 64 KB

Model View ViewModel design pattern on the example of Nine Men's Morris game, using different strategies

Home Page: https://mentalmove.github.io/Mills/

JavaScript 88.13% CSS 6.69% HTML 5.18%
mvvm model-view-viewmodel nine-mens-morris webworker node-cli

mills's Introduction

Nine Men's Morris (Mills)

This project has two purposes:

  • Being a playable game human vs. machine
  • Being a demonstration of the Model-View-ViewModel design pattern with a hopefully meaningful use purpose

 

Abstract

In a Model-View-ViewModel (abbreviated MVVM) - project, code is strictly separated into different sections:

  • The Model section, responsible for the logic (not necessarily the so-called business logic)
  • The View section, enabling interaction with the user
  • The ViewModel section, linking between both by sending and receiving messages

Model and View do not know each other; they communicate indirectly with the aid of the ViewModel. Compared to other design patterns, Model is a little less than a backend (because it must not make its own decisions but has to wait until invoked), and View is a little more than a display section (because it may contain its own logic which has to be related to user interaction tasks).
In this realisation, ViewModel represents a guard over the game's rules, deciding which player may continue, which moves are allowed etc.

 

Pros and Cons

Using MVVM is always a little more complex than executing subsequent code directly, and the application usually performs a little slower. It requires a higher abstraction level when designing the project.
On the other hand, it enables to treat different sections separately what might be useful when maintaining or extending the application. To demonstrate this possible advantage, I created three different versions, sharing parts of the other ones:

Javascript Browser Version and Console Version share (almost) the same Model, having different Views.
PHP Browser Version and Javascript Browser Version share exactly the same View, having different Models.
All versions have at least more or less the same ViewModel in common.

 

Usage of Javascript Browser Version (branch master)

  • Download project and execute file index.html in a browser of your choice

OR

mills's People

Contributors

mentalmove avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

wser

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.