【正文】
boolean seedless。 public void grow() { log(Grape is growing...)。 } public void harvest() { log(Grape has been harvested.)。 } public void plant() { log(Grape has been planted.)。 } public static void log(String msg) { (msg)。 } public boolean getSeedless() { return seedless。 } public void setSeedless(boolean seedless) { = seedless。 } } 類 Strawberry 的源代碼 public class Strawberry implements Fruit { public void grow() { (Strawberry is growing...)。 } public void harvest() { (Strawberry has been harvested.)。 } public void plant() { (Strawberry has been planted.)。 } } ? FruitGardener 類的源代碼 public class FruitGardener { public static Fruit factory(String which) throws BadFruitException { if ((apple)) { return new Apple()。 } else if ((strawberry)) { return new Strawberry()。 } else if ((grape)) { return new Grape()。 } else { throw new BadFruitException(Bad fruit request)。 } } } 簡單工廠模