Details
-
Type: Improvement
-
Status: Open
-
Priority: Major
-
Resolution: Unresolved
-
Affects Version/s: 1.0-beta-5
-
Fix Version/s: 3.0
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Environment:all
-
Number of attachments :
Description
By design, there are implementation dependencies between a factory and its adapter. Every time you create a new adapter, you need to create a new factory, which has zero reuse potential. Parrallel class hierarchy.
First mentioned:
http://lists.codehaus.org/pipermail/picocontainer-dev/2003-November/001606.html
(see followup as well).
It would be a good idea to fix this in one go together with
PICO-90 (http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-90)
as these two issues are somewhat related.
Activity
Aslak Hellesøy
made changes -
Field | Original Value | New Value |
---|---|---|
Assignee | Jon Tirsen [ tirsen ] | |
Fix Version/s | 2.0 [ 10411 ] |
Jörg Schaible
made changes -
Assignee | Jon Tirsen [ tirsen ] |
Michael Rimov
made changes -
Fix Version/s | 2.0 [ 10411 ] | |
Fix Version/s | 2.2 [ 14251 ] |
Michael Rimov
made changes -
Fix Version/s | 2.3 [ 14303 ] | |
Fix Version/s | 2.2 [ 14251 ] |
Michael Rimov
made changes -
Fix Version/s | 2.4 [ 14362 ] | |
Fix Version/s | 2.3 [ 14303 ] |
Michael Rimov
made changes -
Fix Version/s | 2.4 [ 14362 ] | |
Fix Version/s | 2.5 [ 14424 ] |
Paul Hammant
made changes -
Fix Version/s | 2.5 [ 14424 ] | |
Fix Version/s | 3.0 [ 14410 ] |
every time you have a new kind of component you need a new adapter and a new factory. Furthermore, you *can't freely swap* (all factories have an explicit implementation dependency on an adapter). The responsibility split between adapter and factory is in some way broken. One option is to change the relationship: for example from
factory creates adapter
to
factory uses adapter
The combo I like best atm is
adapter uses factory
where a factory is just that, a factory, and the adapter handles everything but the 'new' (and with non-type-3 IoC, the init and dispose). Furthermore, the container need not care or know about factories...
container uses adapter
...is enough.
In my pet container I went further and introduced many-to-many selection policy, where an adapter is associated with a selector inside the container:
Container-<<uses>>----
0..m--->SelectorSelector-
<<locates>>1------>AdapterAdapter-
<<uses>>----1..n--->FactoryThis is essentially a more generic form of a hashmap. In JDK-1.5 terms, the less generic hashmap variant is:
container<key,adapter>
Adapter has-a Factory
In Ruby terms, the selector list functions as a rich switch/case statement, and the selector is the implementation of the '===' operator.
In pseudocode (fragments):
Container.get(arg):
for each selector
if selector.select(arg)
return adapters.get(selector).get()
return null
SingleUseAdapter.get():
return factory.newInstance()
SingletonAdapter.get():
lazyInit()
return instance
Factory.newInstance():
return new Something
Much cleaner. IoC.