我有兩個類:實體類是否可以在OOAD中返回其他實體實例?
public class Car
{
private int id;
private String name;
private String vendor;
/* ... */
}
public class Garage
{
private int id;
private String name;
private String address;
/* get-set and others stuffs */
public boolean addCar(Car c) {
/*
This will insert a car to tblCars
but belong to this garage
*/
}
public List<Car> getListCar {
/*
This will perform a SELECT query on tblCars
to choose cars belong to this Garage
*/
}
}
是它允許在OOAD?
謝謝,我的意思是,例如,在三層設計模式中,表示層不應直接調用數據訪問層,而是通過控制層,因此,這些規則是否禁止一個實體調用/訪問/返回其他實體? – 2013-05-03 13:01:47
視圖應該沒有對控制器的引用(在MVC中)。箭頭應該從控制器中查看。 – 2013-05-03 13:14:00
它旨在顯示信息流,而不是依賴關係 – duffymo 2013-05-03 13:56:40