• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Factory - How to?

 
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>
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic