1

subclassResponsibility sender selector stuck even when subclasses have the method implemented.

I think the argument may cause this happen but is it?

and could anyone tell us why?

in abstract class we have this

fromString: aString
    "init with a string"

    ^self subclassResponsibility

and I am running this:

unit := (Units new fromString: aString)

then error occurs.

In which Units is the abstract class.

Travis Griggs's current approach could remove the error yet

are there doubledispatch for the instance creation method?

marsrover
  • 424
  • 5
  • 16

1 Answers1

6

Kind of shy on details up there, but it looks like it's doing exactly what you told it to.

The expression Units new returned a new Units instance and then you sent fromString: to that. Which you've implemented to return the result of sending subclassResponsibility.

If Units were truly an abstract class, I wouldn't have expected you to instantiate it (you don't generally send new to abstract classes, unless you're also messing with the behavior of new).

So I would have expected you to do something like:

unit := (YourRealSubclass new fromString: aString)

And that YourRealSubclass has a real implementation of fromString:

Travis Griggs
  • 21,522
  • 19
  • 91
  • 167