Hi,
I have a query regarding how the value objects( model objects) should be designed?
Let us say I have Country, State, District, City and I need to build the model objects for these.
My country Model object (CountryVO.java)will have
My State Model object (StateVO.java)will be havingCode:private int countryId; private String CountryName; //other details
Case 1:
case 2:Code:private int stateId; private String stateName private int countryId; private String countryName;
Problems with Case 1:Code:private int stateId; private String stateName private CountryVo countryVO;
Disadvantage:
So, for the City object (Country->State->District->City)there will be lot of variables in the model object
also, if we want more details in the (like one variable for number of people in all these) we need to add one for each(like populationInCity,populationInDistrict,populationInState,populationInCountry) in the city model object.Code:private int cityId; private int cityName; private int disctrictId; private int districtName; private int stateId; private String stateName private int countryId; private int countryName;
Advanteges: looks good while retrieving the details
Code:cityVo.getVCountryId();
Case 2:
Advantage:
The cityVo will have district reference, district will have state reference, state will have country reference.
so the city Model object will look like
I feel this is neat when compared to the case 1.Code:private int cityId; private String cityName; private DistrictVO districtVO;
Disadvantage:
While retriecing the details, we need to do multiple level of delegation
to get the countryName from the cityModelObject
Code:cityVo.getDistrictVO().getStateVO().getCountryVO().getCountryName();
Can anyone please help me in finding the best OO way(either case 1 or case 2) to build these kind of model objects?




Reply With Quote