How and where to handle collisions? [Java] [duplicate]

This question is an exact duplicate of:

Okay, so in my game I have a Level class, which hold an ArrayList of entities. In addition to this, I store the Player here (naturally enough). In my Entity class, I have a method which checks for collisions. This method looks like this:

public boolean collision(Entity other) {
return cBox.intersects(other.cBox);
}


Now, in my Level class, under the update() method, I check for collisions like this:

for (int i = 0; i < entities.size(); i++) {
if (entities.get(i).collidable() && entities.get(i).collision(player)) {
player.notifyCollision();
}
}


The notifyCollision() method simply ticks a boolean named collision to true in the player class.

This leads me to the question: If I have, say a Chest, an Enemy and some Spikes, where all of them are entities on a map (every entity except for the player is part of the entities ArrayList under the Level class), how would I handle the collisions, and where would I do this?

Say that I want to open a chest if the player is standing in front of it, or hurt the player if it collides with an enemy etc. Would I simply go with the notifyCollision() method, and then have another method named handleCollisions() in the Player class, which would be called if a collision were notified? Or would I have a handleCollision() method under the Chest, Enemy and Spike class, and handle them from here?

Because, the question is really how and where to handle the collisions.

marked as duplicate by MichaelHouse♦Apr 4 '15 at 21:41

This question was marked as an exact duplicate of an existing question.