Apologies for the potentially super simple question. I am trying to understand OOP. I have gone through tutorials but many of them are hyper simplified and by giving myself a 'real' project I am hitting obstacles most tutorials don't seem to cover. Heres a scenario I kind of wish to understand:
If I was making a very basic sports game (think Fifa) I currently have 3 objects:
- Object of Pitch
- Object of Team
- Object of Player
I am hitting my first wall of understanding because I don't want player to simply be an extension of team. After all in real life we would all be objects of human with an attribute that tells us which team we belong to before we are a sub object of a team.
What is the best practise for this?
Should I be:
- Creating the objects of player and then adding each object to an array which is stored against the team object? This is how I would do it procedurally.
- Storing the team against the player.
- Storing the player against the team.
- Extending player by team (I want to avoid this unless its actually the done thing)
This is just a brain exercise right now so I don't really have code but
$team1 = new teamObject('red');
$player1 = new players('John');
$team1->addToTeam($player1);
This strikes me as it wouldn't work because in the teamObject Class I wouldn't be able to call any of the Player classes function on the passed player function?