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?
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
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@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
"Ben" == Ben Coman btc@openInWorld.com writes:
Ben> doh! <smacks-head> funny how it works itself out when you step away for a Ben> while - this works fine...
Ben> B class >> relations Ben> (self == B) Ben> ifTrue: [ ^ { E-> #addE. } ] Ben> ifFalse: [ ^ {} ]
Ben> but I still wonder if it is the right approach
Without further analysis, or description of the problem you're trying to solve, this already looks far too fragile for me.
For one, it fails the "null subclass" test. You should always be able to subclass a class, putting no methods in the subclass, and the subclass and superclass objects would be completely interchangeable.
beginners@lists.squeakfoundation.org