Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

need help with parent child relationship

cr0ak3rcr0ak3r Member Posts: 1
i am trying to write a game.
i have two classes. one is characters and one is weapons.
each character has a weapon. and the weapon needs to be able to affect the characters stats. how do i manage that?

i tried inheritance. having the weapon inherit from character so it could access the characters stats, but that only let me change the character class itself and not an instance of it.

anybody got a solution to this?

Comments

  • htakeuchihtakeuchi Member Posts: 19
    : i have two classes. one is characters and one is weapons.
    : each character has a weapon. and the weapon needs to be able to affect the characters stats. how do i manage that?
    :
    : i tried inheritance. having the weapon inherit from character so it could access the characters stats, but that only let me change the character class itself and not an instance of it.

    [red]Do not use inheritance to model interaction between two objects. That is a fundamental design error. Inheritance models [b]differences[/b] between object structures and behaviors.
    [/red]
    [blue]Here are some possibilities...

    1) Handle the updating of character stats in the character class only. Call one or more weapon methods to get the actual change values.

    2) Have a weapon method take a stats object, and return an updated stats object.
    [/blue]
Sign In or Register to comment.