(Last Revision: 11/09/2005)

Discussion of Classes


Information Hiding

The database we are working with is a multi-linked structure. It links data together in many different ways to express different relationships among the data elements. We need to have one data set with three major kinds of operations implemented on this data: It may not be in keeping with the best principles of information hiding to put all those operations inside just one class. But if we use separate classes, how can all the methods operate on the same data? Below I relate one way to accomplish that. The idea is to create three classes that can all operate on the same array of "nodes".

I build "nodes" in layers. I have a class "FamInfo" with three string data members: one for first name, one for last name, and one for storing a search key: the upcase version of the last name with the upcase version of the first name appended to it. I also have a class TreeNode. Each TreeNode contains a "FamInfo" and an array of seven integers which are used as pointers:

typedef enum {leftL, rightR, mother, father, mSib, pSib, child} ptrNameType ;
typedef int ptrArrayType[7] ;


I also have a class called SpaceNode. Each SpaceNode contains a TreeNode plus a bool "inUse" flag and an int "link" field which my program uses to link the elements of the free list together.
NodeSpace

In your solution program you can declare a NodeSpace class. It can have data members: and methods: You can also declare a tree class and a sibling ring class that are friend classes to the NodeSpace class. In the main function of the program, you can declare a NodeSpace object - let's call it theNodeSpace.
myTreeCls

My tree class could have data members: Some of the methods of my tree class can be: You can write the constructor so that it takes a parameter which is a pointer to a NodeSpace. Then in the main function of the program, you can have statements like:

NodeSpace theNodeSpace ;
myTreeCls theTree(&theNodeSpace);


If you set it all up correctly, this will make the pointer in theTree point to theNodeSpace so it can use theNodeSpace as the place where all the tree nodes "live". Methods of myTreeCls can use the operations of the NodeSpace class to allocate and deallocate memory, and so forth.
sibRingClass

The sibling ring class could have data members: Some of the methods of the sibling ring class could be: The implementation can be set up so the same NodeSpace is shared by the tree object and all sibling ring objects.

In my design of the solution code, methods in the tree class declare ring objects when needed. For example, when a method in the tree class needs to merge two sets of siblings, it creates two sibling rings and uses a ring method to merge them into one ring.

The constructor of the ring class gives a ring a specific NodeSpace, value for "startPtr", and value of "next". These things are parameters of the constructor. This allows objects of the ring class to share the same NodeSpace with the tree. It also allows a ring to represent any maternal or paternal sibling ring contained in the database.

The program creates sibling ring objects as needed - using whatever start node is desired. Then the program uses sibling ring methods to help complete ring-oriented tasks that need to be done as part of executing the basic command set of the program -- for example printing the elements of a ring.