Tags | architecture |
Software architecture is a pretty vast topic. This here is just scratching the surface. One good rule of thumb when you are starting is:
Architect your code so that it is testable.
If your code is easy to test then that has a bunch of benefits:
Here’s an example. Imagine you are writing an app that has a user interface. The user interacts with the GUI and then the stuff drawn on the GUI gets updated.
This can be separated into multiple layers. You can think of a data layer and a GUI layer.
If your data and your GUI get all mixed up then things get very hard to test. Here’s an approach you might consider:
function drawPlayerDetails(player) {
document.getElementById("showDetails").innerHTML =
"<strong>Player Name: </strong>" + player.name +
"<br><strong>Points: </strong>" + player.totalScore +
"<br><strong>Position: </strong>" + player.pos +
"<br><strong>scores: </strong> [" + player.score + "]";
}
This function does one thing, and it does that thing well and intuitively.