/* Fish.java*/
package cn.by.DesignModel.TemplateMethod;
/**
 *
 * 抽象模板类
 */
abstract class Fish {
 /**
  * 模板方法
  */
 void oneDay() {
  swim();
  eat();
  sleep();
 }
    
 // 已实现方法
 void swim() {
  System.out.println("I am swimming!!!!");
 }
 void eat() {
  System.out.println("I am eat grass");
 }
    // 各子类不同的方法
 abstract void sleep();
}
 
 
/* GrassFish.java*/
package cn.by.DesignModel.TemplateMethod;
/**
 *
 * 具体子类
 */
public class GrassFish extends Fish{
 void sleep() {
  System.out.println("I sleep at pond( 池塘 )");
 }
}
 
 
 
/*SharkFish.java*/
package cn.by.DesignModel.TemplateMethod;
/**
 *
 * 具体子类
 */
 class SharkFish extends Fish {
 
 void sleep() {
  System.out.println("I sleep at ocean!!!!!!");
 }
}