The Artima Developer Community
Sponsored Link

Object design

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Object design

Posted by Bryan E. Boone on 25 Aug 1998, 11:37 AM

Wouldn't this be more likely?

class Person {
public void listenToPhone(Telephone t) {
t.addTelephoneListener(
new TelephoneAdapter() {
public void telephoneRang(TelephoneEvent e) {
System.out.println("I'll get it!");
((Telephone)e.getSource()).answerPhone();
}
}
);
}
}

class AnsweringMachine implements TelephoneListener {
private int count = 0;
public void telephoneRang(TelephoneEvent e) {
System.out.println("AM hears the phone ringing.");
if(count > 4) {
((Telephone)e.getSource()).answerPhone();
}
count++;
}
public void telephoneAnswered(TelephoneEvent e) {
System.out.println("AM sees that the phone was answered.");
count = 0;
}
}

Your example has the phone answering itself.




Replies:
  • Good Point Bill Venners 02 Sep 1998, 5:25 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us