Java Reference
In-Depth Information
Method 2
For this method, no separate Account class is used. Instead, the data and methods
associated with an individual account will be defi ned directly in the implementation
class. The interface will make the methods available to client processes. The same
four steps as were identifi ed in Sect. 5.2 must be carried out, as described below.
1. Create the interface.
The same fi ve methods that appeared in class Account in Method 1 are declared, but
with each now declaring that it throws a RemoteException .
import java.rmi.*;
public interface Bank2 extends Remote
{
public int getAcctNum()throws RemoteException;
public String getName()throws RemoteException;
public double getBalance()throws RemoteException;
public double withdraw(double amount)
throws RemoteException;
public void deposit(double amount)
throws RemoteException;
}
2. Defi ne the implementation.
As well as holding the data and method implementations associated with an indi-
vidual account, this class defi nes a constructor for implementation objects. The
method defi nitions will be identical to those that were previously held within the
Account class, of course.
import java.rmi.*;
import java.rmi.server.*;
public class Bank2Impl extends UnicastRemoteObject
implements Bank2
{
private int acctNum;
private String surname;
private String fi rstNames;
private double balance;
//Constructor for implementation objects…
public Bank2Impl(int acctNo, String sname,
String fnames, double bal) throws RemoteException
{
acctNum = acctNo;
surname = sname;
fi rstNames = fnames;
balance = bal;
}
Search WWH ::




Custom Search