Spring原理自我实践之IOC的模拟实现
2009-09-18 00:00:00 来源:WEB开发网Interfaces:定义的接口
Java代码
package com.java.interfaces;
import com.java.beans.WheelImpl;
public interface Car {
void setId(String id);
String getId();
void setColor(String color);
String getColor();
void setWheel(WheelImpl wheel);
WheelImpl getWheel();
}
Java代码
package com.java.interfaces;
public interface Wheel {
void setId(String id);
void setSize(String size);
}
Classes:接口对应的实现类
Java代码
package com.java.beans;
import com.java.interfaces.Car;
public class CarImpl implements Car {
private String id;
private String color;
private WheelImpl wheel;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public WheelImpl getWheel() {
return wheel;
}
public void setWheel(WheelImpl wheel) {
this.wheel = wheel;
}
}
Java代码
package com.java.beans;
import com.java.interfaces.Wheel;
public class WheelImpl implements Wheel {
private String id;
private String size;
@Override
public void setId(String id) {
// TODO Auto-generated method stub
this.id = id;
}
@Override
public void setSize(String size) {
// TODO Auto-generated method stub
this.size = size;
}
public String getId() {
return this.id;
}
public String getSize() {
return this.size;
}
更多精彩
赞助商链接