Should EventArgs contain EventArgs?

100 Views Asked by At

I'm writing a particle system and have a hierarchy of one emitter containing many particles.

Particles fire an event on collision with the world:

public event EventHandler<HitWrapperArguments> onHitCallback;

I am in the process of having the emitter subscribe to each particle so it can fire an event when any particle collides:

public event EventHandler<ParticleHitWrapperArguments> onParticleHitCallback;

My question is:

Should my ParticleHitWrapperArguments contain the HitWrapperArguments, or should I unpack HitWrapperArguments and put the collision information directly into ParticleHitWrapperArguments?

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

Personally it doesn't matter too much to me, but I would go for 2.

It just looks cleaner and I think it will be easier in use. It does need additional coding which could result in extra mistakes, but I wouldn't worry to much about it.

0
On

There is no correct answer but I would say use option 1. It is less work and thus less error prone, and it will leave you with a structure resembling the order of creation which will make it easier to debug (think inner exceptions). If you change your structure you would have to perform minimal changes on the wrapping args class, just one example of how it is better design.

If you have to do any processing on the arguments at this stage however, then of course perform these operations and store the new results in your new args object.