上一页 1 2 3 4 5 6 7 8 下一页
package com.javapatterns.simplefactory;
public interface FruitIF { void grow();
void harvest();
void plant();
String color = null; String name = null; } | 代码清单1. 接口FruitIF的源代码。这个接口确定了水果类必备的方法:种植plant(),生长grow(), 以及收获harvest()。
package com.javapatterns.simplefactory;
public class Apple implements FruitIF {
public void grow() { log("Apple is growing..."); }
public void harvest() { log("Apple has been harvested."); }
public void plant() { log("Apple has been planted."); }
public static void log(String msg) { System.out.println(msg); }
public int getTreeAge(){ return treeAge; }
public void setTreeAge(int treeAge){ this.treeAge = treeAge; }
private int treeAge; } | 代码清单2. 类Apple的源代码。萍果是多年生木本植物,因此具备树龄treeAge性质。
上一页 1 2 3 4 5 6 7 8 下一页 |