instantiation - Pattern for building object collection with interdependencie -
on multiple projects in involved, faced same situation : build object family xml data or database.
for instance, can consider e-commerce entities :
- model entities : product, category, price, customization, ... (each entity identified id).
- some 'complex' relationships between entities :
- product has category, price, list of customization, list of recommended products
- category can have parent category
- ...
now want load object representation of xml data. depending on xml schema, happens entity building has relation toward entity not yet created.
facing scenario, end kind of strategy :
- having dictionary each entity type, can reach object knowing id,
- for each relationship, having list> represents "this object has missing relationship, have resolve later object having id"
so, when building object :
- if property id refering object, corresponding dictionary id. if found, property set. if not found, store in
- i add object reference dictionary (however object complete or not), , continue following object
when objects built, there still missing relation. iterate on lists , resolve .
i found quite ugly :
- a lot of code (which not understandable team),
- a lot of dictionary , list,
- probably poor performances
is there common/good pattern situation ? way creational patterns or ioc me (can't see how) ?
there 2 parts problem:
1) maintaining tree of objects (strict aggregation or containment) 2) maintaining network of objects.
if use technology such jaxb construct tree xml file, solving (1), need make couple of additional passes a) build dictionary , b) resolve references solve (2).
the advantage approach jaxb well-maintained technology, and, arguably, well-documented. 80% of problem in hand, can craft documentation second part.
Comments
Post a Comment