

| Visible within the declaring class and to selected other classes or operations. |
| Visible everywhere that the class is visible. |
| Visible only within the declaring class. |
| Visible within the declaring class and in all its sub-classes. |
SoundStage?
interface
and a class.

He suggested that I start using the following generalization:

Do you agree with him? Why or why not?
JMUmble. In this
system, arriving messages are handled by a PostOffice
object. Depending on how the system is configured at runtime, one or
more objects might need to know when a message arrives. I have
currently implemented several such classes:
ScreenFlasher (which makes the entire screen flash --
you always know when a message has arrived),
PopularityTimer (which starts a clock that show the
amount of time since the most recent message arrived), and
Mumbler (which uses speech generation to read the name
of the person that sent the message -- this is where the system got
its name). Use the observer pattern to develop a class model of
this system (in UML). You do not need to include the attributes of
each class, only the operations/methods. Include comments that
describe each operation/method.
GateListenerDatabase class so that it is impossible
to construct more than one instance of it. Use the
singleton pattern.
import java.util.*;
/**
* A database of GateListenerRecord objects
*
*/
public class GateListenerDatabase
{
private Hashtable db;
/**
* Construct a new GateListenerDatabase
*/
public GateListenerDatabase()
{
db = new Hashtable();
}
/**
* Add a GateListenerRecord to the database
*
* @param glr The record to add
* @return true if successful and false otherwise
*/
public boolean add(GateListenerRecord glr)
{
boolean added;
GateListenerRecord old;
String key;
added = false;
key = glr.getHost()+":"+glr.getPort();
old = (GateListenerRecord)(db.get(key));
if (old != null) {
added = false;
} else {
added = true;
db.put(key, glr);
}
return added;
}
/**
* Drop a GateListenerRecord from the database
*
* @param glr The record to drop
* @return true if successful and false otherwise
*/
public boolean drop(GateListenerRecord glr)
{
boolean dropped;
Object oldkey;
String key;
key = glr.getHost()+":"+glr.getPort();
oldkey = db.remove(key);
dropped = true;
if (oldkey == null) dropped = false;
return dropped;
}
/**
* Returns an Enumeration containing all of the GateListenerRecord
* Objects in the database
*
* @return The Enumeration of records
*/
public Enumeration getAll()
{
return db.elements();
}
}

Shape |
Line |
Rectangle |
Text |
Drawing |
operation() |
Copyright ©2004