/* Thursday am lecture - Part 1: Circularly Referential Data --- CSU213 Fall 2006 Lecture Notes --------- Copyright 2006 Viera K. Proulx, et. al. Lecture 15: October 11, 2006 Circularly Referential Data */ class Author{ String name; Book book; Author(String name){ this.name = name; this.book = null; } // add the book the author wrote void add(Book book){ this.book = book; } } class Book{ String title; Author author; Book(String title, Author author){ this.title = title; this.author = author; this.author.add(this); } } class Examples { Examples() {} Author dh = new Author("DH"); boolean testAuthor1 = (check this.dh.name expect "DH") && (check this.dh.book expect null); Book geb = new Book("GEB", this.dh); boolean testAuthor2 = (check this.dh.name expect "DH") && (check this.dh.book.title expect "GEB")&& (check this.dh.book expect this.geb); boolean testBook = (check this.geb.author.name expect "DH") && (check this.geb.title expect "GEB") && (check this.geb.author expect this.dh); Author dh2 = new Author("DH"); Book geb2 = new Book("GEB", this.dh2); boolean test1 = check geb2 expect geb; }