#Inheritance question

1 messages · Page 1 of 1 (latest)

fair musk
#

I have a Placeable that has an enum of types:

{
    Unit,
    Obstacle,
    Building,
    Spell
}
protected PlaceableType placeableType;```

I have a Unit and a Spell that both inherit from `: Placeable` and have an enum of `States`

Those `States` are slightly different, as will other things be obviously.
 (e.g. `Unit` has `attack move, etc... ` where `Spell` has `range, effect, etc...`)

When I create a Fireball or Warrior, should the Fireball or Warrior inherit from `Fireball : Placeable` | `Warrior : Placeable` or  their respective sub class  e.g. `Fireball : Spell` | `Warrior : Unit` ?

I am asking as I'm trying to design it so that when creating a prefab,  **I can just select the enum dropdown of Placeable types and that assigns the States specific to the type**. E.g. Create an Ice spell, select `Spell` from the placeable dropdown and be aware of those states or Archer for Unit, etc.
mossy yew
#

is a fireball a spell?

fair musk
#

yes

mossy yew
#

there's your answer

fair musk
#

-_- that's fair

mossy yew
#

though, i'm not seeing what use that enum has at all

fair musk
#

What do you mean?

mossy yew
#

that enum seems unnecessary

#

though just as an aside - sometimes for prefabs, composition works better than inheritance, since there's kind of already a chain of inheritance within the prefab

fair musk
#

If the designer creates a placeable prefab, Units and Spells are placeables. They would also share a state logic.

mossy yew
fair musk
#

Can you clarify composition - do you mean as additional components

mossy yew
#

yeah

fair musk
#

gotcha