How can I refactor the following code:
class ModifyTree{
public void doActionsOnTree(Tree tree) {
rAction1(tree.getRoot());
rAction2(tree.getRoot());
}
private void action1(Node node) {
// do something with node;
}
private void action2 (Node node) {
// do something with node
}
private void rAction1(Node node) {
action1(node);
for(Node nodeIterator : node.getChildren())
rAction1(nodeIterator);
}
private void rAction2(Node node) {
action2(node);
for(Node nodeIterator : node.getChildren())
rAction2(nodeIterator);
}
}
Methods rAction1()
and rAction2()
looks very similarly. Is there a way to don't repeat the code in this case?