关于接口的问题,接口在下面的代码中的作用??
看到一个别人设计的东西,然后有点疑惑.
Org代表组织.
设计中 Org代表的是接口,主要是对org中的属性进行操作,Dborg是org的实现
OrgManager代表对org进行操作的方法也是接口,DbOrgManager是对OrgManager的实现.
现在看到代码如下:
代码一:
public Org createOrg(String aOrgname, long aSuperiorOuid)
throws OrgAlreadyExistsException{
Org newOrg = null;
try {
if(this.getOrg(aOrgname,aSuperiorOuid)){
//The org already exists since now exception, so:
throw new OrgAlreadyExistsException();
}else{
newOrg = new DbOrg(aOrgname, aSuperiorOuid);
}
}catch (OrgNotFoundException unfe) {
SkinUtils.getLogger().debug(unfe.getMessage());
}
return newOrg;
}
这里返回是接口org的类型,但是程序中返回的是Dborg类型,那么是不是程序自动将
org下塑造型.
代码二:
public void deleteOrg(Org aOrg) throws UnauthorizedException {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = ConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ORG_BY_OUID);
pstmt.setLong(1, aOrg.getOuid());
pstmt.execute();
}catch( SQLException sqle ) {
SkinUtils.getLogger().debug(sqle.getMessage());
}finally {
try { pstmt.close();
}catch (Exception e) { SkinUtils.getLogger().debug(e.getMessage()); }
try { con.close();
}catch (Exception e) { SkinUtils.getLogger().debug(e.getMessage()); }
}
}
其中org是接口,难道接口也可以实例??还是其中aOrg只是org接口的实现的一个实例
请高手指点!!!!!!!!!!!!!