parent previous next question (Smalltalk Textbook 47)

EngiClassGraph & EngiClassGraphModel

This is the final section of the series on grapher libraries which started with section 39. I'd like show you a graphical browser which displays the inheritance hierarchy and lets you browse it. The graphical browser is composed of 'EngiClassGraph' and 'EngiClassGraphModel'. File in Appendix 30 and 31.

At first try to display a class inheritance hierarchy tree. Program 47-1 displays 'Magnitude' inheritance hierarchy in the active window.


Program-47-1: (EngiClassGraph, Magnitude; anyButtonPressed)
-----------------------------------------------------------------
    | classGraph activeWindow activeSensor |
    classGraph := EngiClassGraph fromClass: Magnitude.
    activeWindow := classGraph class activeWindow.
    activeWindow clear.
    classGraph display.
    activeSensor := activeWindow sensor.
    [activeSensor anyButtonPressed] whileFalse.
    activeWindow display
-----------------------------------------------------------------

The program uses 'EngiClassGraph fromClass:' to create a graph of 'Magnitude'.

'EngiClassGraphModel' adds the user interface to the grapher. Program 47-2 displays a class inheritance hierarchy tree whose root is 'Collection'.


Program-47-2: (EngiClassGraph, EngiClassGraphModel, Collection)
-----------------------------------------------------------------
    | classGraph |
    classGraph := EngiClassGraph fromClass: Collection.
    EngiClassGraphModel openOn: classGraph
-----------------------------------------------------------------

The program opens a window named 'Inheritance' with the 'Collection' inheritance tree and allows you to browse it. Select a class by clicking on it. Now select 'browse' from the yellow button menu to open a browser on each of the selected classes. The 'arrange' sub menu accesses graph layout parameters. Try each one.

Now, let's examine the details. Both 'EngiClassGraph' and 'EngiClassGraphModel' are simple and small programs because their super classes have most of necessary structures and functions defined as classNode ('EngiClassVertex') and classArc ('EngiClassBranch').

The ClassGraph definition is :


Program-47-3: (EngiDirectedGraph, EngiClassGraph)
-----------------------------------------------------------------
EngiDirectedGraph subclass: #EngiClassGraph
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Engi-Inheritance'
-----------------------------------------------------------------

There are no instance or class variables. It has three important class methods. 'classHierarchy:' returns the inheritance hierarchy for a given class. Inspect the message below.

----------------------------------------------------------------
EngiClassGraph classHierarchy: Number
----------------------------------------------------------------

You'll get the following result which is a list structure of pairs of a class symbol and it's sub class symbols.

-----------------------------------------------------------------
 OrderedCollection (
. #Object
.  OrderedCollection (
. . #Magnitude
. .  OrderedCollection (
. . . #ArithmeticValue
. . .  OrderedCollection (
. . . . #Number
. . . .  OrderedCollection (
. . . . . #Fraction )
. . . .  OrderedCollection (
. . . . . #Integer
. . . . .  OrderedCollection (
. . . . . . #LargeNegativeInteger )
. . . . .  OrderedCollection (
. . . . . . #LargePositiveInteger )
. . . . .  OrderedCollection (
. . . . . . #SmallInteger ) )
. . . .  OrderedCollection (
. . . . . #LimitedPrecisionReal
. . . . .  OrderedCollection (
. . . . . . #Double )
. . . . .  OrderedCollection (
. . . . . . #Float ) ) ) ) ) )
-----------------------------------------------------------------

This next message returns the subclass hierarchy.


Program-47-4: (EngiClassGraph, subclassHierarchy:)
-----------------------------------------------------------------
EngiClassGraph subclassHierarchy: Number
-----------------------------------------------------------------

And this one returns the superclass hierarchy.


Program-47-5: (EngiClassGraph, superclassHierarchy:)
-----------------------------------------------------------------
EngiClassGraph superclassHierarchy: Number
-----------------------------------------------------------------

So, you've probably guessed that 'classHierarchy:' is a union of 'subclassHierarchy:' and 'superclassHierarchy:'. Therefore a class message named 'fromClass:' is responsible for converting the inheritance hierarchy list structure to the link structure of nodes and arcs for the graph.

Let me turn to the ClassGraphModel. The Class definition:


Program-47-6: (EngiGraphModel, EngiClassGraphModel;)
-----------------------------------------------------------------
EngiGraphModel subclass: #EngiClassGraphModel
    instanceVariableNames: ''
    classVariableNames: 'MenuForClassGraph '
    poolDictionaries: ''
    category: 'Engi-Inheritance'
-----------------------------------------------------------------

The model has a class variable named 'MenuForClassGraph' to cache the yellow button menu. And it has some additional methods to handle yellow button menu items.

That is all I will say about the grapher libraries. Try to make programs which use the grapher libraries like the inheritance browser I introduced in this section. You can make graphical editors such as Entity-Relation-Diagram or State-Transition-Diagram. It is also possible to make a editors for Object Oriented Analysis and Design diagrams or CASE tools.


parent previous next question
Copyright (C) 1994-1996 by Atsushi Aoki
Translated by Kaoru Rin Hayashi & Brent N. Reeves