面向对象(模板方法模式)

面向对象(模板方法模式)

/**
* Created by rabbit on 2014-07-21.博客园.刘朋程
*/
//Created by rabbit on 2014-07-21.博客园.刘朋程
abstract class GetTime
{
    public void getTime()
        {
        long start = System.currentTimeMillis();
            record();
        long stop = System.currentTimeMillis();
        System.out.println("毫秒:"+(stop-start));
        }
    public abstract void record();
}
//Created by rabbit on 2014-07-21.博客园.刘朋程
class SubTime extends GetTime //继承父类将抽象方法record进行复写,定义程序
{
    public void record()
    {
        for (int x=1;x<1000;x++)
        {
              System.out.println("*");
        }
    }
}
//Created by rabbit on 2014-07-21.博客园.刘朋程
public class TemplateDemo {
    public static void main(String [] args)
    {
        SubTime gt = new SubTime();
        gt.getTime();
    }

}

你可能感兴趣的:(面向对象)