[1194] in java-interest

home help back first fref pref prev next nref lref last post

Why do Interface methods have to be public?

daemon@ATHENA.MIT.EDU (Sid Conklin)
Fri Aug 25 17:32:09 1995

Date: 25 Aug 1995 10:39:24 -0700
From: "Sid Conklin" <sid.conklin@nora.stanford.edu>
To: "java-interest@java.sun.com" <java-interest@java.sun.com>

I've build a layered client application that uses interface methods for a
lower level class to callback the high-level class to write itself.  

Low Level (Command)

public write(fileOutputStream iNetStream, CommandObj iObj)
{
	this.writeHeader(iNetStream,...)
	iObj.write;
}

High Level (Service)
{
/* Instance variable*/
Socket NetConnection;

/* Constructor */
public Service()
{
	Command theCommand = new Command(...);
	NetConnection  = new Socket(...);
	theCommand.write(NetConnection.outputStream)
}

/* method called from lower routine when the object should write itself out
the 
public void write()
{
	NetConnection.outputStream(...)
}

Inteface (CommandObj)
public interface CommandObj
{
	public write()
	public read()
}


In this example the Command class only knows how to read/write header
enevelop information for the network command. When it is time to write the
object, the command class class the iObj to write itself out. 

The method Service.write() however shouldn't be public since it will only be
called by the lower level class. I've tried to make it private and it
compiles but then latter blows up in the interpeter with a memory crash.

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post