// The "Basket" example to illustrate an simple usage of // DAJ. // The class graph: // has-a with a label: -label-> // is-a : -<:- // Basket -p->Pencil // -f->Fruit -w->Weight -i->int // \-<:- Orange -c->Color -s->String // class Basket { Basket(Fruit _f, Pencil _p) { f = _f; p = _p; } Basket(Fruit _f, Fruit _f2, Pencil _p) { f = _f; f2 = _f2; p = _p; } Fruit f, f2; Pencil p; } class Fruit { Fruit(Weight _w) { w = _w; } Weight w; } class Orange extends Fruit { Orange(Color _c) { super(null); c=_c;} Orange(Color _c, Weight _w) { super(_w); c = _c;} Color c; } class Pencil {} class Color { Color(String _s) { s = _s;} String s; } class Weight{ Weight(int _i) { i = _i;} int i; int get_i() { return i; } } class BasketMain { static public void main(String args[]) throws Exception { Basket b = new Basket(new Orange(new Color("orange"), new Weight(5)), new Fruit( new Weight(10)), new Pencil() ); BasketVisitor bv = new BasketVisitor(); b.t1(bv); int totalWeight = bv.returnValue(); System.out.println("Total weight of basket = " + totalWeight); b.t2(bv); totalWeight = bv.returnValue(); System.out.println("Total weight2 of basket = " + totalWeight); } }