Consider you wanting to implement a simple game of checkers. There would be a rectangular game board and the player would able to move the pieces around according to a particular set of rules.
I general, good design principles suggest that we decouple the presentation of the game, from it's data and business logic.
That is, the display of the game board and the ability to click and move stuff around would be decoupled from the actual representation of a game board in memory. The data in memory doesn't know what displays it.
Now, let's talk about JavaScript specifically. JavaScript is a language designed mainly to be used as a lightweight client-side language. (I know, JS has grown far beyond it's original intended usage, but it is still generally regarded and used as what I described).
This means that, by it's nature, JavaScript is very coupled to the Html and Css; the GUI. That is it's nature.
So my question is: when designing a client-side JavaScript app, how loosely coupled should I make the business logic and data, and the user interface?
Should I make an effort to entirely decouple the parts, as I would have done in a C# app? Or is it okay for there to be the 'natural' coupling between the logic and display, that feels 'natural' when using JavaScript?
Aucun commentaire:
Enregistrer un commentaire