Java/Abstract Classes
From charlesreid1
Example: defining an abstract Tree type that implements abstract methods for some of the methods required by the Tree ADT:
- element()
- root()
- is_root
- parent
- num_children
- is_leaf
public abstract class Tree {
abstract Node root();
abstract Node parent(Node n);
abstract int num_children(Node n);
abstract Node children(Node n);
abstract boolean is_leaf(Node n);
abstract int length();
abstract boolean isEmpty();
// positions() - iteration of all Nodes in the tree
// iter() - iteration of all elements in the tree
}