I am trying to write some Deterministic Finite Automaton related algorithms. So the obvious start is to define the entities: DFA
, State
and Edges
. However, I though since the DFA
is a kind of graph I should have basic classes Graph
, Node
and Edge
each implementing IGraph
, INode
and IEdge
. And then have DFA
and State
extend Graph
and Node
.
So the stripped down code of Graph
is:
class Graph
{
//...
public void addNode(INode node)
{
//...
}
//...
}
Now the main difference between State
and Node
is that State
adds properties isFinalState
and isStartingState
to Node
. So I want State
objects to be added to the DFA
not the Node
objects through Graph
's addNode()
method.
I thought I can override and make this method private
in DFA
and have defined a new method addState()
which will accept State
objects. But reducing the visibility of parent class members in derived class is not allowed in Java.
So what is the standard solution / approach followed in such scenarios. Or am I thinking this all wrong?
Aucun commentaire:
Enregistrer un commentaire