Re: [morph-developer] appendDefaultComponents WAS Re: Copying Objects to Maps
Brought to you by:
orangeherbert,
sgarlatm
|
From: Matt B. <gud...@ya...> - 2007-03-09 21:04:26
|
I realize you're not yet back, Matt, but I've been
thinking about this stuff and wanted to publish my
latest thoughts:
--- Matt Sgarlata
<Mat...@wh...> wrote:
> Matt Benson wrote:
> > Yeah, I thought about that, but wouldn't that be
> kind
> > of expensive having to add the default converters
> > every time?
> Good point. To get around this overhead, we could
> cache the full list
> of components inside the object. For example, we
> could introduce a new
> transient variable called something like
> allComponents or something that
> was cleared out whenever a call to setComponents was
> made.
This could be okay, but read on...
>
> > Especially given the caveat that we're
> > probably best off always calling
> > createDefaultComponents() and thus instantiating
> new
> > component converters every time (because nothing
> would
> > stop a user from making changes to converters
> obtained
> > from getConverters() if we were to e.g. use
> statically
> > defined components).
> I'm not sure I fully understand what you're saying
> here, but if the
> concern here is that someone would call
>
> getComponents()[0] = Something.class
>
> I think that is probably an edge case. We can just
> state in the
> documentation that if you are messing with
> components you should call
> setComponents.
I could live with that... keep going...
> > Plus we still then have to make
> > the unilateral decision that a cloned SDT instance
> has
> > appendDefaultConverters set to false to make it
> work
> > right with the Composite framework, despite the
> fact
> > that a user-requested clone() operation probably
> wants
> > a true clone, appendDefaultComponents and all...
> you
> > know?
> >
> I did notice after I sent my original email that
> specialization is done
> using the CloningSpecializer. If we want to
> continue using that
> specializer we'd have to override the clone method
> like this:
>
> public Object clone() throws
> CloneNotSupportedException {
> SimpleDelegatingTransformer clone =
> (SimpleDelegatingTransformer)
> super.clone();
> // can't call setComponents because this could
> append the default
> components again
> clone.components = getComponents();
> return clone;
> }
Here is where I still have a problem. Okay, with your
clone() impl above, lets assume
appendDefaultComponents is a property, and that it is
set to true for this instance. The clone would still
have it set to true. If a user called setComponents()
on the clone, it would behave appropriately by
appending the default components. However, if the
CloningSpecializer was the caller, it would call
setComponents with the specialized subset of classes,
but SDT would then append the default components
again, which is incorrect. :( But if you declare
that clones will always have appendDefaultComponents
set to false, the CloningSpecializer works, but now
what's the point of having it be a property at all?
The cloned instance would have the unexpected (from a
user perspective) behavior of NOT appending default
components on subsequent calls to setComponents. I
just don't see yet how we can do this without making
the API confusing or inconsistent in some way. An
alternative might be some kind of extra interface in
the Composite project, but this idea feels kind of
hacky. :(
-Matt B
> > -MJB
> LOL, my middle initial is J too.
;)
>
>
-------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get
> the chance to share your
> opinions on IT & business topics through brief
> surveys-and earn cash
>
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> morph-developer mailing list
> mor...@li...
>
https://lists.sourceforge.net/lists/listinfo/morph-developer
>
____________________________________________________________________________________
Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097
|