#subclassResponsibility (was Re: [squeak-dev] Everyone's talking about debuggers these days)

Frank Shearar frank.shearar at gmail.com
Sun Jan 27 08:34:42 UTC 2013


On 27 January 2013 00:23, Ron Teitelbaum <ron at usmedrec.com> wrote:
>
>
>> -----Original Message-----
>> From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
>> bounces at lists.squeakfoundation.org] On Behalf Of Frank Shearar
>>
>> On 25 January 2013 22:29, Casey Ransberger <casey.obrien.r at gmail.com>
>> wrote:
>> > Inline, briefly.
>> >
>> > On Jan 25, 2013, at 1:55 PM, Frank Shearar <frank.shearar at gmail.com>
>> wrote:
>> >
>> >> By "stub out stuff" do you mean "write a stub test case with self
>> >> assert: false"? *raises hand*
>> >
>> > Actually, I do that when I'm feeling responsible, as in
> I-might-want-to-use-this-
>> more-than-once. More often though, I'm dinking around on Project Euler and
>> plan to throw my code away, in which case I just paste in "self break."
>> >
>> >> Annoyingly, defining a #subclassResponsibility method destroys my
>> >> flow: the debugger won't, obviously, prompt you for that "create
>> >> method" button I love so much. (Hm, could one restore that with a
>> >> SubclassResponsibilityException that the debugger can catch?)
>> >
>> > I'm not sure what the right way to do that would be, but I feel your
> pain. Try
>> it?
>>
>> So actually the UI part is really easy, thanks to Debugger >>
>> #buildNotifierWith:label:message:. I now have a nice Create button, it
> calls the
>> correct method... but I'm a bit stumped. I can record in the call of "self
>> subclassResponsibility" the class and selector that needs implementing
> (stored in
>> a SubclassResponsibilityError), and this causes the debugger to pop up...
> but I
>> don't know how to get a handle on the SubclassResponsibilityError itself
> to find
>> out what to do.
>>
>> Any ideas? (I've scratched around a fair bit with exception handling and
> the
>> Debugger, but this is one step beyond me right now.)
>
> Hi Frank,
>
> I'm not sure I understand what you are having trouble with, but if I needed
> to build a specific handler for subclassResponsibility I would create a new
> class:
>
> Error subclass: #SubclassResponsibilityError
> ...
>
> You could then change
>
> Object>> subclassResponsibility
>         "This message sets up a framework for the behavior of the class'
> subclasses.
>         Announce that the subclass should have implemented this message."
>
>         self error: 'My subclass should have overridden ', thisContext
> sender selector printString
>
> To:
>
> Object>> subclassResponsibility
>         "This message sets up a framework for the behavior of the class'
> subclasses.
>         Announce that the subclass should have implemented this message."
>         SubclassResponsibilityError new
>                 parentClass: thisContext sender;
>                 methodSelector: thisContext sender selector printString;
>                 signal: 'My subclass should have overridden ', thisContext
> sender selector printString.
>
> Now you can build a handler to do whatever you want it to do.  That will
> give you a specific error object for this type of error.
> Does that answer your question?
>
> All the best,
>
> Ron Teitelbaum

Hi Ron,

I've done exactly that, actually - that's the easy part :) So on the
Debugger side there's the existing #createMethod. I've added a hook
that will, on a SubclassResponsibilityError, add a button that
triggers a new method, Debugger >> #createOverridingMethod. My problem
is that with #createMethod you find out the name of the missing
selector by getting self contextStackTop tempAt: 1..

And that's exactly the trick, I suspect:

Object >> #subclassResponsibility
  | exception |
  exception := SubclassResponsibilityError blah.
  exception signal.

That allows you to access the exception itself (and hence the info it
stores) through self contextStackTop tempAt: 1.

Thanks!

frank

>> frank
>>
>
>
>


More information about the Squeak-dev mailing list