ObjectsInstancesRelationshipsConnections

An exploration through the world of Objects, instances; Relationships and connections.

Friday, December 02, 2005

OiRc-0007 Properly untangling the Gordian knot

Regardless of however many levels of Relationships lie between the Objects, you still need a way to array all of them in an orderly fashion.

Topological sorting of all of the objects is the only way to accomplish this, sorting objects topologically close to their owners. (You would probably want to add methods to disambiguate or perhaps sort the objects.)

In Smalltalk this is probably best described by:

 topologicalSort: aDAGInADictionary
"input aDAGInADictionary -> a Dictionary of all the nodes in the system
it associates a node label with a collection of its dependent nodes"
| virgins nodesInReverseOrder visitBlock |
virgins := aDAGInADictionary keys.
nodesInReverseOrder := OrderedCollection? new. "unless you're sorting 'em"
visitBlock := [:aNode |
virgins remove: aNode. "another one bites the dust"
(aDAGInADictionary at: aNode) do: [:anArray |
anArray do: [:anotherNode |
(virgins includes: anotherNode)
ifTrue: [visitBlock value: aNode]]].
"add me after all of my successors and their successors, etc.
have been added"
nodesInReverseOrder add: aNode
].
aDAGInADictionary keys do: [:aNode |
(virgins includes: aNode)
ifTrue: [visitBlock value: aNode ]].
^nodesInReverseOrder reverse "but not if they're being sorted"

Simple and elegant, no?

Of course how you define the Dictionary which is the parameter to the method is everything.

It must consist of entries associating each the Objects to which each node entry to which it is related.

Since I hadn't fully evolved the concept of Relationships back when I was writing this, it is incomplete and in I would be in need of a patron to keep me alive while I untangle the web we weave, when first we practise to reveal.


Suffice it to say that each Relationship from one Object to another should be represented as a fully formed line instance, arrayed between each object.

I have given some thought about how these should be drawn and I will reveal it in a few days, after I get out of school and have more time to devote to the answer.

0 Comments:

Post a Comment

<< Home