This is a very simplified example but it of course extends to more complicated contracts too, I just haven't found an elegant solution.
contract Group {
struct Person {
uint age;
bytes32 name;
}
mapping (address => Person) members;
}
contract RockBand {
struct Musician {
uint age;
bytes32 name;
bytes32 instrument;
}
mapping (address => Musician) members;
}
contract FootballClub {
struct Player {
uint age;
bytes32 name;
bytes32 position;
}
mapping (address => Player) members;
}
Now it makes sense to me to make a 'library' of sorts out of Group, and inherit from it in the other two contracts. But I haven't found a way to modify a defined struct in a child contract. The best I can come up with is:
contract Group {
struct Person {
uint age;
bytes32 name;
}
mapping (address => Person) members;
}
contract RockBand is Group{
struct MusicianExtra {
bytes32 instrument;
}
mapping (address => MusicianExtra) membersMusicianExtra;
}
contract FootballClub is Group{
struct PlayerExtra {
bytes32 position;
}
mapping (address => PlayerExtra) membersFootbalExtra;
}
This is the same as above functionality wise, but it requires an additional mapping for the extra information. Also it will become confusing and messy in bigger contracts, and it probably is less efficient if you need to look in two mappings instead of one to get the information.
I hope someone in the community has some insight for me.
Thanks! :)