I'm in a software engineering class and I want to practice some skills on the most basic case possible : tic tac toe. I know this is overkill but I want to do it in "proper" OOP.
I designed a class diagram for it but there is one point where I don't clearly see what would be the best design decision.
("Joueur" means "Player", "PlancheDeJeu" means "Game board")
Given this diagram, according to the Expert
, Low coupling
and Strong cohesion
design patterns (sorry if those are not the correct english terms, I am translating) the score should be kept by the user class (Joueur). However, since there is no direct relation between Joueur and Système I don't exactly know how the game could display the score in a clean way. In this diagram, Système would have to ask the PlancheDeJeu object about the score and it would itself have to get it from Joueur. This seems wrong. I am trying to think of how to design an intermediary object that would link Joueur and Système but I can't come up with a good idea.
What would be the best way to go here ?
Thanks !
Best Answer
I would have modeled it this way:
It's hard to analyse coupling and cohesion on such a small example, but I'd say that the score does not belong to a player, but to the game he participates in.
BTW:
Your model says Joueur can access PlancheDeJeu, but not the other way.