overridding without subclassing examples
Brad Fuller
bradallenfuller at yahoo.com
Wed Sep 19 00:57:02 UTC 2007
On Tue September 18 2007, Matthew Fulmer wrote:
> On Tue, Sep 18, 2007 at 03:14:15PM -0700, Brad Fuller wrote:
> > Is there a way to override an instance method w/o subclassing?
> > For instance, class Morph has a method that returns true, but I want the
> > that method to return false when instancing some types of Morphs and
> > others not. (there is no setter/getter for this method.) Is there a way
> > to do that w/o adding a setter/getter to Morph or subclassing the
> > different Morphs?
>
> Your question is pretty vague
>
> I imagine you see something like
>
> isMorph
> ^ true
>
> in class morph, but you want some (or all?) morphs to instead
> use
>
> isMorph
> ^ self isSomethingWeirdHappening not
>
> First you can redefine the method in the appropriate class(es). If you
> want to put this change in a MC package, move it to category
>
> *MyPackage-override
>
> and this method will be stored in the package, and will override
> the existing method when loaded.
>
> Package-level overrides are not recommended, but they are available
But doesn't that just replace the method? I don't want to change the original
class nor do I want to subclass.
More information about the Squeak-dev
mailing list
|