Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Factory - How to?

 
Bruce Ichiban
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I've been reading up on this board about Factories and how they can alleviate the need to have client pass their IDs etc. I think I have the general idea down, but I couldn't find a post about how to actually implement it.
Here is what i think the deal is. Please correct me if I'm wrong.
So I want the client to receive a Factory object initially. The client then uses a Factory.method() to ask for a DataWrapper, lets say. Each client when they connect will get a reference to a unique instance of a DataWrapper. These DataWrappers will share the same instance of some form of Data class.
So my question is, how do you pass back a reference to a unique DataWrapper? You dont want the actual object because then it will have no real link to the Data class and hence, the DB. It seems to me like you want to bind DataWrapper to the rmiregistry, but how do you ensure that a new DataWrapper gets created each time, vs sharing the same one?
Can someone point me in the right direction and/or to an example of a similar idea?
Thanks in advance!
 
Bruce Ichiban
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm - i scoured some of the other boards and found a somewhat related idea that i implemented and it works!
can someone validate it or is working enough proof? ;-) (if it is correct, perhaps this might be a good reference for others?)
<code>
------
In the FactoryInterface and Factory classes:
public WidgetIFace getWidget() throws RemoteException
{
return new Widget();
}
------
In the Widget class:
public class Widget extends UnicastRemoteObject implements WidgetIFace
{
public Widget()
{
super();
}
public String aMethod() throws RemoteException
{
return new String("widget info");
}
}
------
</code>
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your WidgetIface does extend Remote correct? That makes the server have the instance of the class, and the client has a reference to the server object.
By extending Remote you give the client it's own instance that is not shared by anyone.
Good job.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic