Good points, Paul, I definitely agree that this is only for a few key classes, Paul. There is no reason to think at this stage that it would be other than for framework classes. I have to think through whether that would in itself be worthwhile. Thanks for your input.
Jack On Thu, 02 Dec 2004 15:42:09 -0500, Paul Speed <[EMAIL PROTECTED]> wrote: > I don't think weak referencing is going to help you. As Craig > mentioned, an Object is immutably tied to its Class... which is > immutably tied to its ClassLoader. > > If Foo has a reference to Bar and you want to replace Bar's > implementation (BarImpl) at runtime without effecting Foo then you are > going to have to decouple them, by using some sort of interceptor > pattern with dynamic proxies, or what have you. As long as Bar's > interface doesn't change then everything should work. > > And that's not particularly hard. Where it gets interesting is when > setting up this relationship in the first place since you have to give > Foo a proxy implementing the Bar interface instead of a direct reference > to BarImpl. This is where dependency injection could come into play > since it can do whatever pre-processing it wants on the objects before > connecting them together. > > And the real tricky part is synchronizing all of this so that Foo > doesn't get confused if Bar gives it a different answer than it expects > (because it's implementation changed mid-interrogation). > > In the end, you end up with a whole lot of class loaders and extra > synchronization just so you don't have to reload the application space > when one or two classes change. It may be worth it for some key > interfaces, but as a general practice it's probably prohibitively > expensive and error prone. And for those key interfaces, it's almost > always better to have both parties involved in the negotiation, ie: tell > Foo it has a new Bar implementation so it can synch its logic properly. > > -Paul > > > > Dakota Jack wrote: > > > Paul and Craig > > > > I am getting what I expect with the following code (see below), thanks > > to Craig, but not with the code which you can find at > > http://131.191.32.112:8080/classes.zip and I am not sure what the > > difference is. Essentially, I am trying to keep a WeakReference to > > Point classes so that when I update the Point.class I can change the > > classes for all the PointImpl objects out there. Not sure what is > > going wrong. If you could take a peek, that would be great. Thanks. > > > > Jack > > > > package com.crackwillow.deploy; > > > > import java.lang.ref.Reference; > > import java.lang.ref.WeakReference; > > > > public class MyReference { > > public static void main(String [] params) { > > CheckPlease cp = new CheckPlease(); > > cp.setBill("1.01"); > > WeakReference wr = new WeakReference(cp); > > ((CheckPlease)((Reference)wr).get()).setBill("5.03"); > > System.out.println(cp); > > } > > } > > > > class CheckPlease { > > private String bill = "0.00"; > > > > public void setBill(String add) { > > if(add == null) add = "freebee"; > > else bill += " + " + add; > > } > > > > public String getBill() { > > return bill; > > } > > > > public String toString() { > > return bill; > > } > > } > > > > > > > > "You can't wake a person who is pretending to be asleep." > > > > ~Native Proverb~ > > > > "Each man is good in His sight. It is not necessary for eagles to be crows." > > > > ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- "You can't wake a person who is pretending to be asleep." ~Native Proverb~ "Each man is good in His sight. It is not necessary for eagles to be crows." ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]