Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!siemens!news.sprintlink.net!newsfeed.internetmci.com!swrinde!sdd.hp.com!hp-pcd!hp-cv!reuter.cse.ogi.edu!qiclab.scn.rain.com!slc.com!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: Hide Method Senders?
Message-ID: <1995Nov21.181836.190@slc.com>
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <48imf3$knm@neptune.ethz.ch> <48a6nl$lc3@sam.inforamp.net> <48o1sl$qrn@tandem.CAM.ORG>
Date: Tue, 21 Nov 1995 18:18:36 GMT
Lines: 38

Vassili Bykov <vbykov@cam.org> writes:
> cesna@nessie (Matthias Cesna) wrote:
> > [...]
> >How to hide senders to a method. Try
> >
> >   ^self perform: 'aMethod' asSymbol
> >
<snip>
> With the code as it is there will also be problems with performance,
<snip>
> A better way would be to initialize an instance or a class variable
> to hold the selector you want and use the stored symbol, like
> 
>   (class)
>   initialize
>     AMethodSelector := 'aMethod' asSymbol
> 
>   somewhere
>     self perform: AMethodSelector

Rather than introducing a number of class variables, you might use the
constant pool of the compiled method, like this:

    someWhere
      | mySelectors |
      mySelectors := #( 1 2 3 4 5 6 ).  " size as needed "
      1 = mySelectors first ifTrue:
        [ " initialize selectors - only done once "
        mySelectors at: 1 put: 'aMethod' asSymbol.
        " do the rest, too " ].
      self perform: mySelectors first.

This has the nice effect of keeping everything in just one method.

  Cheers,
  Alan
    (standard disclaimer)

