失效链接处理 |
工厂模式实现 PDF 下载
本站整理下载:
提取码:idjb
相关截图:
主要内容:
package com.pb.factory;
/**
* 工厂接口类
* @author Administrator
*
*/
public interface AbstractFactory{
public void getInstance(Car car);
}
package com.pb.factory;
/**
* 工厂实现类
*
* @author Administrator
*
*/
public class CarFactory implements AbstractFactory {
/**
* 工厂生产汽车
*/
@Override
public void getInstance(Car car) {
System.out.println(car.getName() + “,”+"汽车价值" + car.getPrice());
}
}
package com.pb.factory;
import java.io.Serializable;
/**
* 汽车类
*
* @author Administrator
*
*/
public abstract class Car implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private double price;
public Car(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
package com.pb.factory;
/**
* 宝马类
*
* @author Administrator
*
*/
public class BaoMa extends Car {
private static final long serialVersionUID = 1L;
private String baoma;
private double baoMaPrice;
|