Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Why do you pass the object by reference? I don't think it matters in objects. Commented Jun 8, 2012 at 19:43
  • This is a proper answer. You need a collection object that supports Dependency Injection so you can add all kinds of different monsters to the group. Next remove the reference pointer and specify the Monster class as an abstract class to be extended by each type of monster. Commented Jun 8, 2012 at 19:43
  • This answer requires that any code that creates a monster also have access to the MosterTeam Check out my answer. Commented Jun 8, 2012 at 20:04
  • I really don't see the point of using loops every time getTotalHp() is called when you can simply keep totalHp in sync at all times by providing the appropriate class methods. Check my answer. Commented Jun 9, 2012 at 0:58
  • @scaraveos - because the MonsterTeam class doesn't add or remove hp from a monster. It's really stupid to keep a separate variable for holding that value, should you keep all common values in separate variables, you mean? Commented Jun 9, 2012 at 9:53