Да, это нормально, и на самом деле это обычная модель. Иногда вам нужно выполнить некоторую начальную настройку, прежде чем вы сможете начать рекурсию, и поэтому вам нужен метод publi c, который выполняет настройку, и вспомогательный метод, который выполняет рекурсию.
Например, чтобы отобразить дерево с уровни отступа:
Настройка
public void printTree(Node tree) {
// Setup: Start with 0 indentation.
printNode(tree, 0);
}
Помощник
private void printNode(Node node, int spaces) {
// Print the current node.
for (int i = 0; i < spaces; ++i) {
System.out.print(" ");
}
System.out.printf("- %s%n", node.getValue());
// Recursive calls: print the children indented 4 extra spaces.
for (Node child: node.getChildren()) {
printNode(node, spaces + 4);
}
}