Java Reference
In-Depth Information
6.4
Using Factory Objects
In real-world applications, client programs often need to create CORBA objects,
rather than simply using those that have already been set up. The only way in which
this can be done is to go through a published
factory object
interface on the ORB.
For each type of object that needs to be created, a factory object interface must be
defi ned in the IDL specifi cation (on the ORB) and implemented on the server. The
usual naming convention for such interfaces is to append the word
Factory
to the
name of the object type that is to be created. For example, an object of interface
Account
would be created by an
AccountFactory
object. The
AccountFactory
object
will contain a creation method that allows connecting clients to create
Account
objects. The name of this creation method may be anything that we wish, but it is
convenient to prepend the word 'create' onto the type of the object to be created.
Thus, the
AccountFactory
's creation method could meaningfully be called
create-
Account
. Assuming that an
Account
object requires only an account number and
account name at creation time, the
AccountFactory
interface in the IDL specifi ca-
tion would look something like this:
interface AccountFactory
{
Account createAccount(in long acctNum,
in string acctName);
};
This method's implementation will make use of the
new
operator to create the
Account
object. Like our other interface implementations, this implementation must
extend the appropriate
idlj
-generated 'ImplBase' class (which, in this case, is
_
AccountFactoryImplBase
). Following the convention of appending the word
'Servant' to such implementations, we would name the implementation
AccountFactoryServant
. Thus, the implementation would have a form similar to
that shown below.
class AccountFactoryServant
extends _AccountFactoryImplBase
{
public Account createAccount(int acctNum,
String acctName)
{
return (new AccountServant(
acctNum, acctName));
}
}
However, it would appear that we have merely moved the object creation
problem on to the factory interface. Connecting clients cannot create factory
objects, so how can they gain access to the creation methods within such
Search WWH ::
Custom Search