Hi Theo: let's make sure we discuss this on Monday. -- Karl =========================== Hi Theo: do you agree with the argument that for the oo case, the first and most important guideline to programming is a simple application of the LoD? -- Karl // taken from HtDP by Felleisen et al., page 25 Guideline on Auxiliary Functions Formulate auxiliary function definitions for every dependency between quantities mentioned in the problem statement or discovered with example calculations. http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-6.html#node_sec_3.2 // argument: For OO, the LoD implies Guideline on Auxiliary Functions in the sense // that if we minimize LoD violations we are pushed to follow the Guideline. // According to HtDP: The guideline is the first and // most important guideline to programming. We use the same example as in HtDP, but translated to objects. class Ticket { Ticket(double p) {price = p;} double price; double profit(){ // LoD violations: local 0 // LoD violations: in control flow: 2 return this.revenue() - this.cost(); // think of it as (pure oo style): // this.revenue().subtract(this.cost()); } double revenue(){ // LoD violations: 0 return this.attendance() * price; // think of it as: // this.attendance().multiply(price); } double cost() { // LoD violations: 0 return 180.0 + (0.4 * this.attendance()); } double attendance(){ // LoD violations 2 return (120 + ((5.00 - price) / 15) *10); // think of it as: // new Double(120).add(( // (new Double(5).subtract(price)).divide // ^ violation // (new Double(15))).multiply // ^ violation // (new Double(10))) ) } double profit2() { // LoD violations: local 1 // LoD violations: in control flow: 5 return (this.attendance() * price) - // ^ violation (180 + (0.4 * this.attendance())); } static public void main(String args[]) throws Exception { Double d1 = new Double(1); Double d2 = new Double(1); Double d3 = d1 + d2; System.out.println(d3.doubleValue()); Ticket t = new Ticket(5.0); System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2()); t = new Ticket(4.50); System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2()); t = new Ticket(4.85); System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2()); t = new Ticket(5.50); System.out.println(" price " + t.price + " profit " + t.profit() + " " + t.profit2()); } }