aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DataClient - do we need a factory a pattern for Local / Remote mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DataClient - do we need a factory a pattern for Local / Remote mode " Watch "DataClient - do we need a factory a pattern for Local / Remote mode " New topic
Author

DataClient - do we need a factory a pattern for Local / Remote mode

Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
HI Friends,
Do we really need a factory pattern for instantiating a Data or Remotedata object for client servicing in DataClient, or cant i staraight away put in two different constructors for the two modes inDataClient insteac of having a seperate DataFactory class.
Kindly Comment
VikasSood
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Vikas,
the factory pattern is a well-known pattern. And therefore it is a standard solution to this kind of problem.
Here is how it works (actually it's only a "factory method", which is also one of the GoF patterns):

And here is the factory method for the above classes:

That's how it works.
Hope this helps.


Mag
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
Hi Mag ,
thankx for ur inputs.
But what i meant to ask in my original post was that do i need to to have a seperate factory class or just a method in DataCleint will do ?
Vikas
Jeff Song
Greenhorn

Joined: Nov 05, 2002
Posts: 27
I think in Data client will be suitable, because when GUI initialized, it new a Data Client and pass a parameter which indicate local or remote to DataClient instance. DataClient use factory pattern to decide which object(local or remote object) to instance. and the GUI can manupulate the object as the user operaters.
jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Hi,
I too have the same question. What I am doing is..
My main client class is ModeSelectionGUI, which enables the user to select the mode and required fields(for localmode-database file name and for networkmode- server name and portnumber) and connect to the database(I mean Data class) through corresponding client classes. For this I wrote a method connectTODatabase() in ModeSlectionGUI which will check which mode is selected and based on that it invoke the corresponding client class.
I didn't use any Factory Pattern(In separate class, I think I used it in this ModeslectionGUI itself by writing one method) here. Please guide me If I am wrong in my procedure.
Thanks!!!


jyothi
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Jyothi,
what you have done is leaving the job of getting the appropriate (local or remote) object to the user.
This is actually the job of the factory. It returns the appropriate object on the basis of some information. My factory accepted a String parameter. If it started with "//" or contained "://", the factory decided that a remote connection was needed and requested one from the remote server specified by the String parameter.
Check what your instructions say - which parameters are allowed on the command line?
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
Hi Mag,
Thats what i was asking for advice on,i think i got the point of having a factory class helping DataClient get an reference of Data or RemoteData.which is in a way how we are trying to hide the mode of implementation of datbase procedures from user.Which is exactly what sun is expecting us to do.
I will also like to tell u that my Gui is not directly communicating with DataClient ,I am implementing a FlightFacade class which is the only class to which the Gui communicates.
Am i right in my approches above,kindly comment.
VikasSood
[ November 06, 2002: Message edited by: Vikas Sood ]
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi,
Ur GUI class should not directly communicate with facade, instred the controller should communicate and get the result and give it back to GUI.
-rameshkumar
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
Hi ,
If i am getting u correctly u are talking about the Mediater pattern,that is having a centrla controller mediater for the purpose of passing requests from Gui to Facade.
What i am planning to have is that my Facade itself will act like a controller and mediater for this purpose.I dont think there is a need to have any other class for this purpose.
Kindly comment
VikasSood
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi,
Ur facade should not act as a controller. What iam talking here is MVC architecture. So have a controller class which will handle all ur events and based on that it will collect the data from the facade(Model) and update ur GUI(View).
-rameshkumar
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
Hi ramesh,
I think i get u now,What i was thinking of having was planning to have a FlightFacade which acts as a Controller and Model (two in one).And i think u dont have to have seperate classes for implmenting MVC,as most of the swing components are Implementing MVC pattern and have a single class for Model and Controller.
Am i right,comment.
VikasSood
Jeff Song
Greenhorn

Joined: Nov 05, 2002
Posts: 27
Hi!
Can I use a business logical class to get the user input of the GUI and invoke the method of the FlightFacade? Facade redirect the invoation to the real Data Class.
pls comment!
Jeff Song
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hi vikas,
As u said u can have both contoller and model in the same class. But the maintainablity is lost so its better to have it seperately.
Hi Song,
Ur right u can have a class as u said, and name it FBNController.
-rameshkumar
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
hi Ramesh,
I also agree with u in that aspect,and myself might as well go in for implementing MVC using seperate classes for each of them.
Thanks for this discussion.
Vikas
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
Hi Friends ,
Another passing thought,if i am implmenting MVC with three different classes that is Gui ,TableModel & controller .And Controller is using FlightFacade for Access to data services,then my FlightFacade will be acting as a mediater between GUI and DataServices.
Am i right that we are using mvc and mediater pattern over here.
Please Comment.
VikasSood
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Vikas,
in MVC, the controller's job is to react to user input such as mouse clicks. In Java, the controller is often implemented as a kind of action listener.
Hope this helps.
Vikas Sood
Ranch Hand

Joined: Sep 03, 2002
Posts: 109
HI Mark,
Can u plz comment on my above querry ,i am at the moment implementing this face of my assignment, and am a little confused on this aspect,can i mention that i am using MVC with Mediater pattern in my design document.
Vikas Sood
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Vikas,
here's a simple example:

In Java, esp. AWT/Swing, this kind of controller classes are often implemented as anonymous classes:

The model is a data structure. It can be of any format, e.g. an array of DataInfo objects, a Vector, a String (whatever you like).
The view is what you show, e.g. in a JTable.
And the Controller is the object that reacts to user input. For example, if the user double-clicks the line of a table, Java passes on the click event to some listener, which then triggers some action.
Actually, in a normal Swing application, you have a number of controllers, which are often implemented as anonymous classes (see above). Each widget has its own controller.
Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataClient - do we need a factory a pattern for Local / Remote mode