Delegation

Entities act mainly by delegating the work to the grid, state, queue and hatchery objects. That allows convenience methods to be defined in the Cell class:

class Cell<E> {
    private Grid<E> grid;
    ...

    void move(...) { grid.move(...); ... }
}

In fact, by making the fields private, classes which extend Cell are forced to use the convenience methods, which is a good thing because it makes them immune from the details of the grid, state, queue and hatchery objects.

But now we run into a problem. How are the fields in the Cell class to be initialized? The normal way would be through a constructor:

class Cell<E> {
    Cell(Grid<E> g, ...) { ... }
}

But that would mean each extending class would have to have a similar constructor:

class Entity extends Cell<Entity> {
    Entity(Grid<Entity> g) { super(g...); }
}

That would be ugly because (a) we would like to keep custom entity classes ultra-simple by handling as many details as possible in framework classes and (b) custom entity classes would not be completely independent of the details of how the Cell class works.

A solution is to set the fields via a method rather than a constructor:

class Cell<E> {
    void init(Grid<E> g, ...) { ... }
}

Now extending classes can be kept simple, with the init method being called only from the Level class.