Subclassing Dictionary Redux

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Subclassing Dictionary Redux

avalmez
Hello!

Yep I'm having a problem similar to that previously posted about here but the circumstances aren't quite the same and the suggested solutions don't work anyway.  The situation...

I am subclassing Dictionary because i want to code to an "interface" rather than the Dictionary class as I want the flexibility of changing the parent class to some other collection if that seems appropriate. So, I did something like this:

Dictionary subclass: #MySubclass...

All other details of the subclass definition are left to "asis" in the subclass template. However, when is send
Myclass>>at:put: the method fails with error message "only integers should be used as indices".

The proposed solutions to other similar issues reported by others were:

- overide MyClass class>>new as follows:  ^super new initialize (actually, override the parent's new)
- add <shape: #inherit> to the body of the class

I tried the former expecting no change (why should it work?) and my expectation was realized.  The latter doesn't specify where in the class body to add <shape: #inherit> but tried each of the following individually:

- Revised: Dictionary subclass: #MySubclass
                               shape: #inherit...
- Added MySubclass>>shape
                             ^#inherit
-Added MySubclass class>>shape
                                         ^#inherit.

Doubtless someone out there knows what I should have done, but what I did do failed in each case with the same error message.

So, I'm stumped at this point.  I know that adding "index: #object" to the subclass definition works in another implementation of Smalltalk, but Squeak doesn't seem to recognize index:. Still stumped.

One last thing I found while hunting and pecking for a clue that I don't understand.  Squeak documentation states that Dictionary is a subclass of Set, and in other implementations of ST that is indeed the case (I believe the ST standard specifies the same).  However, the system browser shows that Dictionary is a subclass of HashedCollection...???

Enough verbiage.  Any suggestions/fixes folks? All responses will be greatly appreciated.

Andres
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Subclassing Dictionary Redux

Ron Teitelbaum
> From: avalmez
> Sent: Monday, June 13, 2016 6:42 PM
>
> Hello!
>
> Yep I'm having a problem similar to that previously posted about here but
> the circumstances aren't quite the same and the suggested solutions don't
> work anyway.  The situation...
>
> I am subclassing Dictionary because i want to code to an "interface"
rather
> than the Dictionary class as I want the flexibility of changing the parent
class
> to some other collection if that seems appropriate. So, I did something
like
> this:
>
> Dictionary subclass: #MySubclass...


[Ron Teitelbaum]
I tried this and it worked fine.  

Dictionary subclass: #MyDictionary
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Collections-RonTest'

(MyDictionary new) at: 'hello' put: 'world'; yourself

Returns:

a MyDictionary('hello'->'world' )

Not sure what problem you are having but it seems like some of the other
details may be causing the trouble you are seeing.  

What functionality could you possibly be adding to Dictionary that MyClass
with an instance variable #myDictionary can't solve?

All the best,

Ron Teitelbaum

>
> All other details of the subclass definition are left to "asis" in the
subclass

> template. However, when is send
> Myclass>>at:put: the method fails with error message "only integers
> Myclass>>should
> be used as indices".
>
> The proposed solutions to other similar issues reported by others were:
>
> - overide MyClass class>>new as follows:  ^super new initialize (actually,
> override the parent's new)
> - add <shape: #inherit> to the body of the class
>
> I tried the former expecting no change (why should it work?) and my
> expectation was realized.  The latter doesn't specify where in the class
body

> to add <shape: #inherit> but tried each of the following individually:
>
> - Revised: Dictionary subclass: #MySubclass
>                                shape: #inherit...
> - Added MySubclass>>shape
>                              ^#inherit
> -Added MySubclass class>>shape
>                                          ^#inherit.
>
> Doubtless someone out there knows what I should have done, but what I
> did do failed in each case with the same error message.
>
> So, I'm stumped at this point.  I know that adding "index: #object" to the
> subclass definition works in another implementation of Smalltalk, but
> Squeak doesn't seem to recognize index:. Still stumped.
>
> One last thing I found while hunting and pecking for a clue that I don't
> understand.  Squeak documentation states that Dictionary is a subclass of
> Set, and in other implementations of ST that is indeed the case (I believe
the
> ST standard specifies the same).  However, the system browser shows that
> Dictionary is a subclass of HashedCollection...???
>
> Enough verbiage.  Any suggestions/fixes folks? All responses will be
greatly
> appreciated.
>
> Andres
>
>
>
> --
> View this message in context:
http://forum.world.st/Subclassing-Dictionary-
> Redux-tp4900765.html
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Loading...