1.CPU接口
package fire;
public interface CPU {
public void run();
}
2.PCCPU类
package fire;
public class PCCPU implements CPU{
@Override
public void run() {
System.out.println("PC CPU正在运行");
}}
3.MacCPU类
package fire;
public class MacCPU implements CPU{
@Override
public void run() {
System.out.println("Mac CPU正在运行");
}}
4. RAM接口
package fire;
public interface RAM {
public void run();
}
5.PCRAM类
package fire;
public class PCRAM implements RAM{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("PC ARM正在运行");
}}
6.MacRAM类
package fire;
public class MacRAM implements RAM{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Mac ARM正在运行");
}}
7.HardWareFactory接口
package fire;
public interface HardWareFactory {
public CPU produceCPU();
public RAM produceRAM();
}
8.PCFactory类
package fire;
public class PCFactory implements HardWareFactory{
@Override
public CPU produceCPU() {
// TODO Auto-generated method stub
return new PCCPU();
}@Override
public RAM produceRAM() {
// TODO Auto-generated method stub
return new PCRAM();
}}
9. MacFactory类
package fire;
public class MacFactory implements HardWareFactory{
@Override
public CPU produceCPU() {
// TODO Auto-generated method stub
return new MacCPU();
}@Override
public RAM produceRAM() {
// TODO Auto-generated method stub
return new MacRAM();
}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)