Details
-
Type: Test
-
Status: Closed
-
Priority: Minor
-
Resolution: Won't Fix
-
Affects Version/s: 1.0-RC-1
-
Fix Version/s: None
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Environment:JDK 1.4.2
Win2K
-
Number of attachments :
Description
I've been struggling with what to do about the container dependency anti-pattern. I think I see some areas where it might be useful (other than linking parent and child containers), but perhaps some holes can be poked in my approach.
What I've been thinking about is whether it would be useful to have a container manage persistent instances that are part of a domain model. Can/should domain objects be components and would it be worthwhile to allow them to be instantiated with outside dependencies, potentially coming from a hierarchy of containers?
When you have domain objects in a container, they'd most likely be stored using the primary key/object ID as the component key, and thus getComponentInstance(Object key) allows for simple lookup based upon object ID. Now when considering service components that manage domain objects, they'd have a dependency on the domain object container for retrieval. So a question I have is how to structure a service component container in relation to the domain object container?
a. Does the domain object container become a parent of the service component container? or
b. Does the domain object container live inside of the service component container?
The attached test case illustrates these two approaches. (a) corresponds to test 'testShirtQuality2' while (b) is represented by 'testShirtQuality1'. The example may be a bit contrived, but hopefully communicates the idea.
Activity
Field | Original Value | New Value |
---|---|---|
Attachment | SiegerTestCase.java [ 11500 ] |
Attachment | DefaultPicoContainer.patch [ 11501 ] |
Attachment | ShirtFactoryTestCase.java [ 11981 ] |
Resolution | Won't Fix [ 2 ] | |
Status | Open [ 1 ] | Closed [ 6 ] |
Note that the 'testShirtQuality2' test case does not work in the current codebase without the attached patch. What I am trying to illustrate is a way to soften the container dependency by defining a focused interface and having the container implement that interface.
Also, I like the idea of managing component dependencies by having parent containers (in this case the domain object container) manage components in a conceptually separate application layer that are dependencies for components in child containers (the service component container). Is this an appropriate way to structure a layered application?