At the next class this program will be up for discussion. Please study it before class and one or two of you will explain it. ============== If you want to "feel" your objects, display them with the application of the Visitor pattern shown below. The generic team is responsible for generating this kind of visitor code but till they have that, everybody has to write this manually. The Visitor will give output like: A( = B X B{ ~ {C} D( = Ident Ident(ident1) ) E( = Integer Integer(4) ) D( = Ident Ident(ident2) ) E( = Integer Integer(5) ) } X( = Y Y( ) ) ) Run the program yourself in: http://www.ccs.neu.edu/research/demeter/sources/DemeterJava/examples/j-g-displayAsTree ================================= // To demonstrate how to translate class dictionaries // into object displaying visitors A { (@ void g_displayAsTree() { TreeDisplayVisitor pv = new TreeDisplayVisitor(new Integer(0)); this.t(pv); } @) // it is important that you traverse to all classes whose // objects you want to display. If you forget to traverse to // Y, Y-objects will not display. This is an advantage since // you can control with the traversal specification what // to display. // Demeter/Java does not yet allow to traverse to all // classes reachable from A by omitting the to part // (like Demeter/C++ does traversal t(TreeDisplayVisitor pv) { to {D,E,Y};} } Main { (@ static public void main(String args[]) throws Exception { A a = A.parse(System.in); a.g_displayAsTree(); System.out.println("done "); } @) } TreeDisplayVisitor{ (@ void spaces() { for (int i=0; i < indent.intValue(); i++ ) {System.out.print(" ");}} @) (@ void incr() { this.set_indent(new Integer(this.get_indent().intValue() + 3));} @) (@ void decr() { this.set_indent(new Integer(this.get_indent().intValue() - 3));} @) // The class dictionary is translated systematically into // a TreeDisplayVisitor. The class definition is printed // for more context when reading the object. // The class definition // A = "a" B X "enda". // is translated into the following two visitor methods before A (@ spaces(); System.out.println(" A( = B X ");incr(); @) after A (@ decr(); spaces(); System.out.println(" ) "); @) // B ~ "(" {C} ")". before B (@ spaces(); System.out.println(" B{ ~ {C} "); incr(); @) after B (@ decr(); spaces(); System.out.println(" } "); @) // X = "x" Y. before X (@ spaces(); System.out.println(" X( = Y"); incr(); @) after X (@ decr(); spaces(); System.out.println(" ) "); @) // Y = . before Y (@ spaces(); System.out.println(" Y( "); incr(); @) after Y (@ decr(); spaces(); System.out.println(" ) "); @) // D = "d" Ident. before D (@ spaces(); System.out.println(" D( = Ident"); incr(); spaces(); System.out.println(" Ident(" + host.get_ident() + ")"); @) after D (@ decr(); spaces(); System.out.println(" ) "); @) // E = "e" Integer. before E (@ spaces(); System.out.println(" E( = Integer"); incr(); spaces(); System.out.println(" Integer(" + host.get_integer().intValue() + ")"); @) after E (@ decr(); spaces(); System.out.println(" ) "); @) } ----------------------------------------- class dictionary A = "a" B X "enda". B ~ "(" {C} ")". X = "x" Y. Y = . C : D | E. D = "d" Ident. E = "e" Integer. Main = . TreeDisplayVisitor = Integer. ------------------------------------------ input a ( d ident1 e 4 d ident2 e 5 ) x enda