The Account Manager is an example of a factory, in that the person or Automated Teller Machine (ATM) that acts as an account manager controls the creation of and/or access to the individual accounts.
Now once you have a library card, you can go into the library, and then just walk out with all the reference material you want, without any further fuss, right? No of course not. Before you can walk out of the library without setting off the alarm system, you must check out the book or CD or video tape that you wish to take home. So you present your library card to, you guessed it, the librarian, who will use your card to access the library database, to see if you owe any late-fees, and to register these new materials as having been leased to you. So in this case, the librarian could be seen as a book factory because the librarian controls your access to the books.
rmiregistry
)
to get a reference to one of the remote objects, and the rmiregistry
which facilitates the client's ability to initially contact the server.
For the picture below, and the steps that follow, you may make the following assumptions:
Factory
and Product
FactoryImpl
implements the Factory
interface and
the ProductImpl
implements the Product
interfaceFactoryImpl
registers, or is registered, with the rmiregistry
Factory
rmiregistry
returns a remote reference to a FactoryImpl
FactoryImpl
to obtain
a remote reference to a ProductImpl
FactoryImpl
returns a remote reference to an existing ProductImpl
or to one that it just created based on the client requestProductImpl
AccountManager
would be a remote interface with one or
more methods that would return objects that implement the Account
interface. In a similar fashion, Account
would be an interface
that declared all the operations a person could perform on an account instance,
like deposit or withdraw money, get an account balance, or get the most
recent account transactions.
In RMI, only the instance of the AccountManager
implementation
would be registered with the RMI registry. The AccountManager
implementation would be the factory that returned remote references to
(or serialized instances of) Account
implementations, like your
savings account.
Librarian
would be a remote interface
with one or more methods that would return objects that implement the LibraryCard
interface. In addition, the Librarian
interface would have methods
to allow you access to books or CD's or videotapes that implemented the
Loanable
interface.
In RMI, only the instance of the Librarian
implementation would
be registered with the RMI registry. The Librarian
implementation
would be the factory that returned remote references to (or serialized
instances of) LibraryCard
implementations and Loanable
object
implementations.