Details
-
Type: Improvement
-
Status: Closed
-
Priority: Blocker
-
Resolution: Fixed
-
Affects Version/s: 1.0-beta-5
-
Fix Version/s: 1.0-beta-4
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Number of attachments :
Description
Two-way relationships and any form of circularities are hard to maintain. We should not have them unless they are strictly required.
There's also some bugs in the current implementation and how it is used.
These two current situations contradict each other:
- One wants to be able to create a container temporarily with a parent in order to create for example a one-off instance or to keep as a request-scoped container in a web-framework. Without a downlink all you need to do is create that container, use it and the garbage collector will pick it up when it is no longer needed.
To avoid this a weak reference is used from the parent to the children. - In most situations this is not intuitive. For example the XML-parsers (ehm... "front-ends"?) parse the xml-tree and then assume the hierarchy will be intact (for example when calling lifecycle-methods or in the unit-tests to validate the parsing was correct). Unfortunately this cannot safely be assumed.
Personally I find that using weak-references in a design is a smell. It's to be used for system-level things like caching or distributed garbage collection.
I've also encountered some scary issues relating to maintaining these relationship in PicoExtras. It is very common to do "addParent" when what you really want is "setParent", the relationship to the "old" parent is rarely maintained. I believe the relationship is contra-intuitive and we will see problems in the way it is used.
We will see very scary bugs popping up due to all this.
If the parent -> children relationship needs to be maintained I think we should instead provide some form of Builder-class (preferably in PicoExtras) that can be used to build and navigate the entire structure without having to add awkward relationships in the object-model.
I don't think we should release a 1.0 before this is in some way resolved.
Activity
Field | Original Value | New Value |
---|---|---|
Description |
Two-way relationships and any form of circularities are hard to maintain. We should not have them unless they are strictly required. There's also some bugs in the current implementation: The two current situations contradict each other: - One wants to be able to create a container temporarily with a parent in order to create for example a one-off instance or to keep as a request-scoped container in a web-framework. Without a downlink all you need to do is create that container, use it and the garbage collector will pick it up when it is no longer needed. To avoid this a weak reference is used from the parent to the children. - In most situations this is not intuitive. For example the XML-parsers (ehm... "front-ends"?) parse the xml-tree and then assume the hierarchy will be intact (for example when calling lifecycle-methods or in the unit-tests to validate the parsing was correct). Unfortunately this cannot safely be assumed. Personally I find that using weak-references in a design is a smell. It's to be used for system-level things like caching or distributed garbage collection. We will see very scary bugs popping up due to this. I don't think we should release a 1.0 before this is in some way resolved. |
Two-way relationships and any form of circularities are hard to maintain. We should not have them unless they are strictly required. There's also some bugs in the current implementation and how it is used. These two current situations contradict each other: - One wants to be able to create a container temporarily with a parent in order to create for example a one-off instance or to keep as a request-scoped container in a web-framework. Without a downlink all you need to do is create that container, use it and the garbage collector will pick it up when it is no longer needed. To avoid this a weak reference is used from the parent to the children. - In most situations this is not intuitive. For example the XML-parsers (ehm... "front-ends"?) parse the xml-tree and then assume the hierarchy will be intact (for example when calling lifecycle-methods or in the unit-tests to validate the parsing was correct). Unfortunately this cannot safely be assumed. Personally I find that using weak-references in a design is a smell. It's to be used for system-level things like caching or distributed garbage collection. I've also encountered some scary issues relating to maintaining these relationship in PicoExtras. It is very common to do "addParent" when what you really want is "setParent", the relationship to the "old" parent is rarely maintained. I believe the relationship is contra-intuitive and we will see problems in the way it is used. We will see very scary bugs popping up due to all this. If the parent -> children relationship needs to be maintained I think we should instead provide some form of Builder-class (preferably in PicoExtras) that can be used to build and navigate the entire structure without having to add awkward relationships in the object-model. I don't think we should release a 1.0 before this is in some way resolved. |
Fix Version/s | 1.0-beta-4 [ 10412 ] | |
Fix Version/s | 1.0 [ 10145 ] |
Component/s | Core (Java) [ 10191 ] |
Assignee | Jon Tirsen [ tirsen ] |
Assignee | Jon Tirsen [ tirsen ] | Aslak Hellesoy [ rinkrank ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Resolution | Fixed [ 1 ] | |
Status | In Progress [ 3 ] | Closed [ 6 ] |
I've been having some problems fixing this issue. It is common in some unit-tests to navigate the parent -> child-link in order to check that a parsed or created structure is correct.
I think the idea of creating a Builder-class that can be used to build and navigate a container hierarchy is the best solution to this problem.
Suggestions are deeply appreciated!