Late binding class names

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Late binding class names

Sean P. DeNigris
Administrator
How would I hook into the system, let's say during the execution of one particular method (and whatever methods it calls recursively), and substitute one Class for another, without effecting the rest of the system?

For example:
myMethod
    "Until I return, use MyOtherClass instead of MyClass, but only in this thread"

    MyClass doSomething.
    ThirdClass doSomethingElse.

ThirdClass>>doSomethingElse
    "This use of MyClass will also be replaced with MyOtherClass"

    MyClass doAnotherThing.

Thanks.
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Late binding class names

Pavel Krivanek-3
Hi,

I'm pretty sure it is not possibe to do that on classes without VM
modifications. But you may look at WADynamicVariable from Seaside how
to process such context specific globals.

-- Pavel

On Fri, Apr 20, 2012 at 9:27 PM, Sean P. DeNigris <[hidden email]> wrote:

> How would I hook into the system, let's say during the execution of one
> particular method (and whatever methods it calls recursively), and
> substitute one Class for another, without effecting the rest of the system?
>
> For example:
> myMethod
>    "Until I return, use MyOtherClass instead of MyClass, but only in this
> thread"
>
>    MyClass doSomething.
>    ThirdClass doSomethingElse.
>
> ThirdClass>>doSomethingElse
>    "This use of MyClass will also be replaced with MyOtherClass"
>
>    MyClass doAnotherThing.
>
> Thanks.
> Sean
>
> --
> View this message in context: http://forum.world.st/Late-binding-class-names-tp4575026p4575026.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: Late binding class names

Sean P. DeNigris
Administrator
Pavel Krivanek-3 wrote
you may look at WADynamicVariable from Seaside how
to process such context specific globals.
Thanks for the pointer... I checked it out, but Seaside is actually not doing anything with the binding there.

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Late binding class names

Pavel Krivanek-3
On Sat, Apr 21, 2012 at 7:01 PM, Sean P. DeNigris <[hidden email]> wrote:

>
> Pavel Krivanek-3 wrote
>>
>> you may look at WADynamicVariable from Seaside how
>> to process such context specific globals.
>>
>
> Thanks for the pointer... I checked it out, but Seaside is actually not
> doing anything with the binding there.
>
> Sean
>

It does nothing with class bindings directly but it is maybe the
cleanest way how to solve this kind of problem. However if you really
need to switch classes, you may try to sent becameForward: during
context switching in ProcessorSheduller.

-- Pavel

Reply | Threaded
Open this post in threaded view
|

Re: Late binding class names

Prof. Andrew P. Black
In reply to this post by Sean P. DeNigris
Without knowing what you are trying to accomplish, I have to bee too critical, but have you though about doing something much simpler, using say the state patterns, and delegating this method to another "state" object.

I'm particularly scared by the idea that the same object will have two different classes in two different threads.

        Andrew
 
On 20 Apr 2012, at 12:27 , Sean P. DeNigris wrote:

> How would I hook into the system, let's say during the execution of one
> particular method (and whatever methods it calls recursively), and
> substitute one Class for another, without effecting the rest of the system?
>


Reply | Threaded
Open this post in threaded view
|

Re: Late binding class names

Sean P. DeNigris
Administrator
Andrew P. Black wrote
Without knowing what you are trying to accomplish, I have to bee too critical
Thank you for your concern, Andrew ;-)

Of course, in normal programming, your point would be well-justified, but in this case, I'm implementing a test double library, so I specifically want to protect the rest of the system while a TestCase partially stubs out the functionality of a class (e.g. return a canned value for DateAndTime>>now). But it seems that this would be too difficult, so I'll probably resort to method wrappers. It's not as sandboxed, but it's much simpler.

Sean
Cheers,
Sean