There are different ways of implementing component systems so how you get hold of other components may vary. It also depends on how you implemented you game object model. That is where the objects are stored and how to get hold of them.
I’ve implemented GameObject as an actual java class that contains a list of components. My components may also have methods. As an example:
class RenderComponent extends Component {
...
// called every frame
public void update() {
// owner is the GameObject that this component is part of
PositionComponent posComp = getOwner().getComponent(PositionComponent.class);
if (posComp != null) {
renderAt(posComp.x, posComp.y, posComp.z);
}
}
}
My GameObjects are store in a world that I can get hold of from the component. So if the player component wants to get hold of the positions of all the powerups I could write:
class Player extends Component {
...
// called every frame
public void update() {
// a reference to the world is given to the component when it was added to the world
for (Powerup powerup : getWorld().getComponents(Powerup.class)) {
PositionComponent posComp = powerup.getOwner().getComponent(PositionComponent.class);
if (posComp != null) {
// do something with the powerup
}
}
}
}
You should also read the Game Object Component System thread.