The OO structure of your data
You have identified several classes in your Character
population, that are derived from the abstract role , namely Attack
, Defense
and Support
. Each kind of role has different attributes depending on the class.
So you have clearly an OOP design in your mind and want to implement it in a database. Several design patterns could be used :
- The easiest seems to be the single table inheritance puts all the fields in a single table. These are used/interpreted depending on the concrete role.
- The class table inheritance puts the data related to each role (and the character itself) in a distinct table. This requires a 1:1 relation between the derived class' table (e.g.
Defense
) and the parent class table (here Character
). This seems an overkill here
- The concrete table inheritance merges the parent classes with the most derived classes, so you'd end up with a table per role, each having its own
name
field. Again, this seems an overkill here.
Classes or relations ?
There is another additional model that you could consider. It's a component like design, based on composition (in the SQL schema on relations):
- You would have one
character
table with an id
, name
and role
- You would have a property table with the character's
id
, a property-id
(or name) and a value
.
This could be advised if you want to be very flexible and creative and invent additional properties (e.g "has weapon A", "has weapon B", "armor strength", etc.). However if you intend to stick relatively closely to the current properties, this would be overkill again.
No-SQL
If you'd like to consider a non relational database, typically a No-SQL database, then you could consider document based databases which are perfectly suited to handle structures similar to the single inheritance table.
If you opt however on component design, then key-value stores could also be a choice, but you'd still have to assemble the pieces. That's the cost of the extra flexibility ;-)
You said polymorphism ?
Polymorphism is rather on the behavior that is related to the class rather than the data that describes the objects. As it is not question of behavior here, I guess that you'd meant the handling of the different kind of data (so it's more about classes). Let me know if I'm wrong on this point.
You should however let the polymorphism in the question, because it could help other people who are less aware of OOP terminology to find solutions to similar problems