package kata.gameoflife.a20170806; /** * Game of Life Kata. * Copyright (c) 2017, Peter Kofler, licensed under BSD License. */ public class ClassifyPopulation implements Classify { private final int numberOfAliveNeigbours; public static ClassifyPopulation havingNeighbours(int count) { return new ClassifyPopulation(count); } private ClassifyPopulation(int numberOfAliveNeigbours) { this.numberOfAliveNeigbours = numberOfAliveNeigbours; } @Override public boolean asOptimal() { return !asUnderpopulated() && !asOverpopulated(); } private boolean asUnderpopulated() { return numberOfAliveNeigbours < 2; } private boolean asOverpopulated() { return numberOfAliveNeigbours >= 4; } // It is having neighbours, but that is an implementation detail. // What it really is doing: checking for under or over population. }