Hello,
Basically I wanted to create a structure that uses the least amount of memory as possible (mostly when persisting an object inside an ArrayList). There for I have create a set of POJO�s.
However I needed to sometimes query these POJO�s, and therefore I have created a set of Helper classes. The helper classes are there just to have methods, that otherwise would be in the POJO objects (but would not let that POJO remain so if that would happen).
I will give a simple example below:
Imaging having an The following POJO�s; Community, Houses, Person. A Community stores House in a List, while House stores Person in a List.
Now Imagine wanting to know how many persons live inside the community�
For this I would have three Helper classes. One called CommunityHelper, the other one HouseHelper, and the otherone PersonHelper (we do not need this one for this example).
HouseHelper naturally has a method called getPersonCount();
CommunityHelper also has a method called getPersonCount() and is implemented as follows:
public int getPersonCount(){
int amm = 0;
HouseHelper helper = new HouseHelper();
Iterator iterator = community.getHouses().iterator();
while(iterator.hasNext()){
helper.setHouse((House)iterator.next());
amm+=helper.getPersonsCount();
}
return amm;
}
No I understand that the above method is very simple (just returning the size of an array list from the helper) however there could be other more complicated methods.
In short my question is the following? Is it a good practice to leave all POJO�s very simple, and then just write a wrapper to handle the methods?
My other alternative was to use inheritance, basically the helper class would extend my POJO class and therefore I would have the POJO + the method in one class.
However I would be happy for any comments.
Regards,
Sim085