The Artima Developer Community
Sponsored Link

Good Point

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:

Good Point

Posted by Bill Venners on 02 Sep 1998, 5:25 PM

> 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.

Yes, except we'd probably want the answering machine to have
some time limit between rings. If someone calls up and rings
twice, then hangs up, the next call won't be answered after
two more rings.

By the way, to enter code into this forum without the indentation
being lost, just surround it with

 and 
.

bv




Replies:

Sponsored Links



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