How about taking this approach?
Then I can do two things. If I want to have a weapon in the game I could subclass TWeapon and assign it to the players weapon field like this:
or I could add a TWeapon field to some other object that I can't subclass from TWeapon. Then assign the TWeapon field within this object to the players weapon field.
This would seem to be pretty flexible. Just add a TWeapon field to any class I want to weaponize.
Wait. Why even sublcass TWeapon for "real" weapons. Maybe TSword should go like this:
Then the assignment to the players weapon field will be consistent with any weaponized object because I am assigning a field of the object to the players weapon in every case.
Type TWeapon method attack() print "attack with weapon" end method end type Type TPlayer weapon : TWeapon method attack() weapon.attack() end method end type
Then I can do two things. If I want to have a weapon in the game I could subclass TWeapon and assign it to the players weapon field like this:
Type TSword extends TWeapon method attack() print "attack with sword" end method end type mysword : TSword = new TSWord player.weapon = mysword
or I could add a TWeapon field to some other object that I can't subclass from TWeapon. Then assign the TWeapon field within this object to the players weapon field.
Type TBook field title : string field contents : string field weapon : TWeapon end type spellbook : TBook = new TBook player.weapon = spellbook.weapon
This would seem to be pretty flexible. Just add a TWeapon field to any class I want to weaponize.
Wait. Why even sublcass TWeapon for "real" weapons. Maybe TSword should go like this:
Type TSWord field weapon : TWeapon end type
Then the assignment to the players weapon field will be consistent with any weaponized object because I am assigning a field of the object to the players weapon in every case.