I would just make an abstract method on the Body object called Collided:
abstract class Body
{
abstract void Collision(Body other);
}
class Dog : Body
{
public override void Collision(Body other) {
this.Bark();
}
public void Bark() { ... }
}
Then in your collision function just call Collision on the involved bodies.
public bool OnCollision(Body body1, Body body2)
{
body2.Collision(body2);
}
This way any type of body can do whatever it needs when a collision happens, you could even optimize this to keep track of which bodies have been notified of collisions with eachother and reduce the number of function calls that you have to execute:
public bool OnCollision(Body body1, Body body2)
{
// Record that these two objects have been notified of a collision
// then when these same objects are the only two operands in subsequent calls
// you can just short circuit the calls.
if(!AlreadyNotifiedOfCollision(body1, body2))
{
body1.Collision(body2);
body2.Collision(body1);
NotifiedOfCollision(body1, body2);
}
}
Of course empirical testing would have to be done to validate that this check is faster than actually just doing the call twice...