1.UML图
2.代码如下
package com.xiaobi.golf.factory.abstractMethod;
/**
* 引擎实体
*/
public interface Engine {
void start();
void run();
}
class LowEngine implements Engine{
@Override
public void start() {
System.out.println("启动的时间久,加速度较慢");
}
@Override
public void run() {
System.out.println("跑的不快");
}
}
class HighEngine implements Engine{
@Override
public void start() {
System.out.println("启动的时间快,加速度大");
}
@Override
public void run() {
System.out.println("跑的快");
}
}
package com.xiaobi.golf.factory.abstractMethod;
/***
* 汽车座椅
*/
public interface Seat {
void chirapsia() ;
void makings();
}
class SheetSeat implements Seat{
@Override
public void chirapsia() {
System.out.println("不会按摩!!");
}
@Override
public void makings() {
System.out.println( "不是真皮");
}
}
class AutoSeat implements Seat{
@Override
public void chirapsia() {
System.out.println( "有自动按摩功能");
}
@Override
public void makings() {
System.out.println( "是真皮的 ");
}
}
package com.xiaobi.golf.factory.abstractMethod;
public interface CarFactory {
Engine createEngine();
Seat createSeat();
}
package com.xiaobi.golf.factory.abstractMethod;
public class LowCarFactory implements CarFactory {
@Override
public Engine createEngine() {
return new LowEngine();
}
@Override
public Seat createSeat() {
return new SheetSeat();
}
}
package com.xiaobi.golf.factory.abstractMethod;
public class HighCarFactory implements CarFactory {
@Override
public Engine createEngine() {
return new HighEngine();
}
@Override
public Seat createSeat() {
return new AutoSeat();
}
}