Skip to main content
added 17 characters in body
Source Link
Madara's Ghost
  • 175.7k
  • 52
  • 274
  • 314

First of all, they're called Objects or Instances, as in Object oriented programming?

Second, nothing is stopping you from creating an array (it does not look weird) of monsters:

$monsters = array( new Monster(), new Monster(), new Monster(), new Monster() ); foreach($monsters as $monster) { $totalHP += $monster->hp; } 

About the unique ID, that one should be the responsibility of the MonsterFactory, meaning, a monster should be assigned an ID, it should not assign it to itself, rather the ID should be assigned to it. Something like this when creating a monster:

new Monster(4); //ID is 4 

Who keeps track of it? Someone else, not the Monster.

First of all, they're called Objects, as in Object oriented programming?

Second, nothing is stopping you from creating an array (it does not look weird) of monsters:

$monsters = array( new Monster(), new Monster(), new Monster(), new Monster() ); foreach($monsters as $monster) { $totalHP += $monster->hp; } 

About the unique ID, that one should be the responsibility of the MonsterFactory, meaning, a monster should be assigned an ID, it should not assign it to itself, rather the ID should be assigned to it. Something like this when creating a monster:

new Monster(4); //ID is 4 

Who keeps track of it? Someone else, not the Monster.

First of all, they're called Objects or Instances, as in Object oriented programming?

Second, nothing is stopping you from creating an array (it does not look weird) of monsters:

$monsters = array( new Monster(), new Monster(), new Monster(), new Monster() ); foreach($monsters as $monster) { $totalHP += $monster->hp; } 

About the unique ID, that one should be the responsibility of the MonsterFactory, meaning, a monster should be assigned an ID, it should not assign it to itself, rather the ID should be assigned to it. Something like this when creating a monster:

new Monster(4); //ID is 4 

Who keeps track of it? Someone else, not the Monster.

Source Link
Madara's Ghost
  • 175.7k
  • 52
  • 274
  • 314

First of all, they're called Objects, as in Object oriented programming?

Second, nothing is stopping you from creating an array (it does not look weird) of monsters:

$monsters = array( new Monster(), new Monster(), new Monster(), new Monster() ); foreach($monsters as $monster) { $totalHP += $monster->hp; } 

About the unique ID, that one should be the responsibility of the MonsterFactory, meaning, a monster should be assigned an ID, it should not assign it to itself, rather the ID should be assigned to it. Something like this when creating a monster:

new Monster(4); //ID is 4 

Who keeps track of it? Someone else, not the Monster.