[Newbies] comparing to an exact class & storing class association relationships

Ben Coman btc at openInWorld.com
Thu Apr 19 11:07:04 UTC 2012


Ben Coman wrote:
> I am trying to record and work with the non-inheritance relationships 
> between classes.  For example I have...
>
> C subclasses B which subclasses A
> E subclasses D which subclasses A
> A <-- B <-- C
> A <-- D <-- E
> with an 1 to N association relationship between B & E.
>
> A class >> relations
>    ^ {}
>
> B class >> relations
>    ^ { E -> #addE: }
>
> the executing 'B relations' returns the list.  Now in terms of the 
> model, it is correct that C inherits the relationship to E,
> but in terms of drawing the class relationships on screen, there 
> should be nothing drawn between C & E.
> The problem is that executing 'C relations' returns { E -> #addE: } 
> but I don't want to draw that.
>
> One fix would be a FORCED requirement to define #relations returning 
> ^{} on EVERY class that does not have its own relations,
> but I want to avoid having to do that.
> Another fix is doing...
> B class >> relations
>    (self isKindOf: B class)
>        ifTrue:  [ ^ {     E-> #addE.  }     ]
>        ifFalse: [ ^ {}  ]
>
> except #isKindOf includes subclasses.  Is there another method that 
> compares to an EXACT class?

doh! <smacks-head>   funny how it works itself out when you step away 
for a while - this works fine...

B class >> relations
   (self == B)
       ifTrue:  [ ^ {     E-> #addE.  }     ]
       ifFalse: [ ^ {}  ]

but I still wonder if it is the right approach

cheers -ben

>
> I have also considered storing a classes relationships in a class 
> instance variable, which I think would work, but it lacks the 
> visibility that doing it in code has. Also I hit the same issue with 
> with lazy initialization of that variable per class.
>
> Or... am I approaching this all wrong?  Is there another way?
>
> cheers, Ben
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list