Say I have set of items defined. Those items have to be grouped into different sets. E.g Items can be like
public Item {
public int id;
public String name;
}
and sets have their own settings like which items belong to this set, what is set's name etc. Now all that stuff is stored in, say xml structure.
My first idea would be to write following elements:
xml parser to get set's data and transform to MySet pojo
xml parser to get all items and transform to list of Item pojos
stateless service-like class say ItemsSetCreator computing final ItemsSet object containing definition of set based on MySet and list of items like
class ItemsSetCreator { public ItemsSet createItemsSet(List<Item> items, MySet set) { // ... } }
But another approach would be to enrich model a bit and write sht like:
MySet class being able to get all the items, apply internal logic to them based on xml-data and provide final ItemsSet as a result
etc.
I don't know which is better one. I know e.g Spring promotes more service centric approach, but there is a lot of buzz recently about avoiding anemic models.