I'm reading a book using VisualWorks and I try to write the code in GNU Smalltalk. I have this:
OrderedCollection subclass: Stack [
push: anObject [
self addLast: anObject.
]
pop [
self isEmpty
ifTrue: [^nil]
ifFalse: [^self removeLast].
]
]
| st |
st := Stack new.
st push: 'a'.
Transcript show: st pop.
but it doesn't work. Can someone please explain me what am I doing wrong?
I'm assuming you're getting Object: Stack error: should not be implemented in this class, use #basicNew instead
?
If so, then it looks like you need to add <shape: inherit>
in the body of your subclass.
See:
That seems like a bit of a leaky abstraction to me - but I guess it is what it is.