WEB开发网
开发学院软件开发Java Spring原理自我实践之IOC的模拟实现 阅读

Spring原理自我实践之IOC的模拟实现

 2009-09-18 00:00:00 来源:WEB开发网   
核心提示: Interfaces:定义的接口 Java代码packagecom.java.interfaces;importcom.java.beans.WheelImpl;publicinterfaceCar{voidsetId(Stringid);StringgetId();voidsetColor(S

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;  
  }  

上一页  1 2 3 4 5 

Tags:Spring 原理 自我

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接