[quote=175521:@Dave S]PERFECT! works just the way I wanted…
and I learned something new… proving you CAN still teach an old dog new tricks (even if he does growl while doing so)[/quote]
I have used that design patterns a number of times… but it seems like a lot more work to set up than it should be.
RB had interfaces from when I first came in (RB3). While you could not do the friend thing back then, I found them very useful from the start!
Well that solved one problem, and now I have created the opposite problem
Same classes as above “A” has a collection of Class “B”
But now if any instance of Class “B” has a property value changed, I need to notify Class “A”
I tried having Class “B” raise an Event, but since the event was in an “instance”, I could determine no way for “A” to see that event.
So I tried to create another Interface
CLASS “B”
SUB shared_code(assigns new_value as string)
Class_A_Interface(shared_code)=new_value // This line generates below ERROR
END SUB
Class “A”
SUB shared_code(assigns new_value as string)
.... do something with new_value
END SUB
Class_A_Interface [implemented by CLASS_A]
SUB shared_code(assigns new_value as string)
ERROR Message in CLASS_B
Assignment accessor must be invoked by assigning a value
and it highlights “shared_code”
I don’t see any part of this that ISN’T assigning a value
[quote=175915:@Dave S]Well that solved one problem, and now I have created the opposite problem
Same classes as above “A” has a collection of Class “B”
But now if any instance of Class “B” has a property value changed, I need to notify Class “A”[/quote]
Why won’t AddHandler work? Assign the Handler from classA To the instance of ClassB when you add the ClassB to the collection.
Alternatively Add a reference to ClassA itself (or a weak reference to it) to each classB instance when added to the handler and use another private Interface to A that allows ClassB to call a Method on ClassA
[quote=175926:@Dave S]so if there are 100 instances of Class_B then I need 100 AddHandlers?
[/quote]
What I do in that case with delegates is not use addhandler. I create 1 delegate instance to the method that I store in the parent Class A (usually created in the constructor). Then when I assign an instance of B to A, I have the instance store a reference to that delegate in a property.
That way I have 100 references to a single delegate instead of 100 independent delegates to the same method on the same instance of Class A
I find that simpler than using AddHandler as I can just Nil the reference in B (or just assign a reference to a delegate from a different parent instance. Besides saving overhead, doing it that way is a bit simpler and more flexible than having to fiddle with RemoveHandler.
That is what I was suggesting alternately if I was not clear… Though Maybe a weak reference would be best… and as I said you can use another private interface to hide the method call from the outside.
[quote=175926:@Dave S]so if there are 100 instances of Class_B then I need 100 AddHandlers?
[/quote]
Oh god …
AddHandler is great for some things but its not a substitute for a well designed API