I have the following class hierarchy for graphs:

```
typedef vector<int> ArrayI;
typedef vector<Array<long>> Mat2DB;
typedef vector<ArrayI> adjList;
class baseGraph {
int nodes;
ArrayI degree;
//some member functions.
}
class matGraph: public baseGraph {
Mat2DB matrix;
//member functions.
}
class lMatGraph: public matGraph {
ArrayI labels;
//member functions.
}
class listGraph: public baseGraph {
adjList list;
//member functions.
}
class lListGraph: public listGraph {
ArrayI labels;
//member functions.
}
```

Now in this class I have many other functions, mostly virtual, so that when I get to call the proper function while using the base class pointer.

For example I have a function `sssp(int node)`

which implements single source shortest path. The implementation are both different for `class matGraph`

and `class listGraph`

which are adjacency matrix representation and adjacency list representation of graphs respectively. Now there is not need to change the definition for labelled version of these graphs so I do not define these functions again in `lListGraph`

and `lMatGraph`

Now the only problem I am havin is with `setLabel(const ArratI &)`

in `lListGraph`

and `lMatGraph`

classes. I need this function to be virtual so that it gets called through base class pointer, but at the same time I do not have anything such as labels for classes `matGraph`

and `listGraph`

.

I do not know if my design hierarchy is correct or not, but it seemed intuitive to me. So any comments on that would be good. What can I do with the `setLabel`

function. Is it okay to have such a function(to me it looks like kind of a workaround so this question) or do I need to reconsider my class hierarchy.

P.S.: I would also love if there are some books from which I can practice design questions like these. I run into these delimma offten and am not sure what to do of them.

EDIT:

Use of class graph is used in another class `clustering`

where I have a member `baseGraph *graph`

i.e.

```
class clustering {
baseGraph *graph;
}
```

I am storing the pointer to base class here so that I can use the different algorithms(implemented as functions) from `class graph`

. For clustering class it again depends what type of graph I want to use.