I'm trying to design my game to be component based rather than overly hierarchical. Essentially, every high level object in the game (like gun, or whatever) inherits and implements the interfaces that it needs. For example, IPhysics, IRenderable, IWeapon, etc.
There are a few cases where I'm uncertain how to obtain a specific interface from another.
For example. A Gun might inherit from IWeapon, IPhysics, and IRenderable. I then also have a player which inherits from IPlayer, IPhysics, and IRenderable. I need a way so that, when Player and Gun collide, if Player is not currently wielding a weapon, he should be able to wield the gun and hold a pointer to the IWeapon of the Gun.
Right now, when Box2D detects a collision between 2 fixtures, I use the UserData field to store the IPhysics pointer associated with the fixture, and therefore, the IPhysics.beginContact method is invoked.
From here, the Player needs to somehow be able to know that this is a weapon, and obtain an IWeapon* . This is the part I really have no idea on.
Any advice on solving something like this is appreciated, even if it means some kind of design change on my part. I'm just looking for a clear way on how to solve this sort of problem.