/* aop program with flexible interfaces and inheritance */ /* binary tree class */ interface tree { int size(); // number of nodes in tree } class nil implements tree { public int size() {return 0;} public static final nil NIL = new nil(); public String toString() { return ""; } } class node implements tree { int head; // data stored in node tree left, right; public node(int h, tree l, tree r) { head=h; left=l; right=r; } public int size() { return left.size() + right.size() + 1; } public String toString() { return left.toString()+head+" "+right.toString(); } } // node /* ****************** */ // The following aspect implements binary search trees, with a // new signature interface searchtree { node lookup(int x); // search for x in tree, return null if not found tree insert(int x); boolean isbst(int min, int max); // check if tree is a search tree } aspect bst { // modify inheritance hierarchy declare parents : tree extends searchtree; // define new methods for each class tree: public node nil.lookup(int x) { return null; } public node node.lookup(int x) { if (x==head) return this; else if (x