Why would this class be abstract?

Amazed

New Member
In my AP Computer Science class, we've been going through the GridWorld case study. While looking at it, it seems that the class AbstractGrid has no reason to be abstract, as it has no abstract methods or values. Why would this be?More informationIf it was just to force implementation of the Grid interface, why doesn't it have those methods as abstract methods (thus forcing the signatures of those classes anyway without the interface). Also, both of the children override most of it's methods anyway.\[code\]package info.gridworld.grid;import java.util.ArrayList;public abstract class AbstractGrid<E> implements Grid<E>{ public ArrayList<E> getNeighbors(Location loc) { ArrayList<E> neighbors = new ArrayList<E>(); for (Location neighborLoc : getOccupiedAdjacentLocations(loc)) neighbors.add(get(neighborLoc)); return neighbors; } public ArrayList<Location> getValidAdjacentLocations(Location loc) { ArrayList<Location> locs = new ArrayList<Location>(); int d = Location.NORTH; for (int i = 0; i < Location.FULL_CIRCLE / Location.HALF_RIGHT; i++) { Location neighborLoc = loc.getAdjacentLocation(d); if (isValid(neighborLoc)) locs.add(neighborLoc); d = d + Location.HALF_RIGHT; } return locs; } public ArrayList<Location> getEmptyAdjacentLocations(Location loc) { ArrayList<Location> locs = new ArrayList<Location>(); for (Location neighborLoc : getValidAdjacentLocations(loc)) { if (get(neighborLoc) == null) locs.add(neighborLoc); } return locs; } public ArrayList<Location> getOccupiedAdjacentLocations(Location loc) { ArrayList<Location> locs = new ArrayList<Location>(); for (Location neighborLoc : getValidAdjacentLocations(loc)) { if (get(neighborLoc) != null) locs.add(neighborLoc); } return locs; } /** * Creates a string that describes this grid. * @return a string with descriptions of all objects in this grid (not * necessarily in any particular order), in the format {loc=obj, loc=obj, * ...} */ public String toString() { String s = "{"; for (Location loc : getOccupiedLocations()) { if (s.length() > 1) s += ", "; s += loc + "=" + get(loc); } return s + "}"; }}\[/code\]
 
Back
Top