先抛开一大堆OOA和OOD的理论, 来点实际的代码:
1, 使用POJO的实体类
Class Worker {
String Name;
... other properties & getter & setter;
}
然后给一个统一接口, HumanService
Class HumanService {
Worker getWorker (Long ID){...}
BigDecimal getSalaryByWorker (Long workerID){
...Look up Ejb to get salary
}
.... 其他方法;
}
使用的时候就是:
getHumanService ().getWorker ();
getHumanService ().getSalaryByWorker();
2. 把Worker类当作一个有行为的实体
Class Worker {
String Name;
... other properties & getter & setter;
BigDecimal getSalary() {
...Look up Ejb to get salary
}
}
然后给一个统一接口, HumanService
Class HumanService {
Worker getWorker (Long ID){...}
}
这里当然就是
Worker = getHumanService ().getWorker(workerID);
if(Worker!=null)
Worker.getSalary() ;
很迷惑, 到底哪个才是OO了? 或者两种都不是?