[squeak-dev] Re: Two methods sharing source code?
elkemann at web.de
Tue Jun 3 19:33:48 UTC 2008
There are many ways in squeak to have code in 1 place but use it from
many. Of course the most standard way is always a shared superclass; if
that is not possible then there are many other ways...
Adrian Kuhn wrote:
> It is as simple as (iff you ignore tool support)
> A compile: 'foo ^ 42'.
> m := A methodDict at: #foo.
> B methodDict at: #bar putNoBecome: m.
> B new bar. "=> 42"
Yep this is fun, and you dont need to learn (proper) Traits.
Make sure everything is still working. In fact SystemBrowser will not
show that B has an instancemethod #bar, you have to register the
selector for it to notice, something like that. And code-repositories
and fileouts/changes might not notice anything, so consider it a hack.
You might think that the method is hidden from the squeak user then but
"B selectors" will return an array of selectors including #bar.
Its also fun: B methodDict: A methodDict :-)
More information about the Squeak-dev