A way to go in which class?

I have 2 classes, player and game, and get_player_games ($ player_id) method. In which class does this method belong?

I seem to have run into this problem a bit when I am not 100% sure which class should use the method. Is this just a matter of preference?

thank

+3
source share
4 answers

I see it as:

A game

The Game class stores information about the game. The game includes current game details such as score, players (in the game), and other details. At the same time, there can be one or more games.

Player

The Player class stores information about the player in the game. The player contains information about the player, such as name, UID, contact, and other information.

, , . .

... ? , , . ? , ...

  • ( )
  • ( , , ..)

, Games, , , , ..

0

- , . , , , .

, , - get_player_games() , . ( ), , . get_game_players() get_games_for_player(), , , .

, , ( , ), , , .

, , , , .

+2

: 1 . 2 . N. ?

: 1 . 2- . N .

, . ? , , .

, -, .

0

Assuming that the object Gamemodels one game, then the method clearly does not belong, since any game will not know other games. It is possible that the object Playercould contain a list of all the games in which the player participated. But the way you posed the question suggests that we do not have a reference to the object Player, but rather to the player’s identifier. Therefore, Playeralso does not work.

It looks like this method will belong to a class with the name MatchHistoryor Tournamentor Ladderor something like that.

0
source

Source: https://habr.com/ru/post/1787255/


All Articles