定义一个操作中的算法骨架, 而将一些步骤延迟到子类中.
举例
/**
* 创建车的抽象类
* @author fan
*
*/
public abstract class Car {
public abstract void Start();
public abstract void Go();
public void dirver() {
Start();
Go();
};
}
/**
* 实体类
* @author fan
*
*/
public class Bc extends Car {
@Override
public void Start() {
// TODO Auto-generated method stub
System.out.println("BC Start");
}
@Override
public final void Go() {
// TODO Auto-generated method stub
System.out.println("Bc go");
}
}
/**
* 实体类
* @author fan
*
*/
public class Bmw extends Car{
@Override
public void Start() {
// TODO Auto-generated method stub
System.out.println("Bmw Start");
}
@Override
public final void Go() {
// TODO Auto-generated method stub
System.out.println("Bmw go");
}
}
/**
* 测试下
* @author fan
*
*/
public class Test {
public static void main(String[] args) {
Car car = new Bc();
car.dirver();
car = new Bmw();
car.dirver();
}
}
// res
BC Start
Bc go
Bmw Start
Bmw go