File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Question on class design for DataClient and Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Question on class design for DataClient and Client" Watch "Question on class design for DataClient and Client" New topic
Author

Question on class design for DataClient and Client

HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi,
I'm having a question on my class design for my client package.
I'm having a ClientGUI class to act as my View/Controller.
And LocalDataClient and RemoteDataClient as my Model (extends Observable).
However, to simplify access from the ClientGUI, I've both LocalDataClient and RemoteDataClient implements an IDataClient interface so that ClientGUI will always use IDataClient irregardless it is a Local or Remote Data.

|->RemoteDataClient
ClientGUI ->IDataClient-|
|->LocalDataClient
Now both my LocalDataClient and RemoteDataClient extends Observable.
Is there a simplier way to simplify this design?
e.g. have an AbstractDataClient that extends Observable.
Then, both LocalDataClient and RemoteDataClient extends AbstractDataClient.
(This design seem to have a problem as the RemoteDataClient need to catch RemoteException but not LocalDataClient.
Or is there another design pattern that solve this problem?
Any comments is greatly appreciated.
Thanks.

Han Ming
HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Opps, sorry that the figure looks distorted as the white spaces is removed.
It should look better this time
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well the diagram looks good. I just don't understand why you extend/implement Observable?
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi Mark,
Thanks for the reply.
I'm extending Observable because I'd like to implement a MVC pattern.
I'd like the LocalDataClient and RemoteDataClient to be my model and the ClientGUI to be the View/Controller.
Thus, my xxxDataClient extends Observable and ClientGUI extends Observer.
But because xxxDataClient implements IDataClient, I have to extends Observable for both Local and Remote DataClient.
I'm wondering if there is anyway to simplify it.
Hmmm, or do you think a MVC is not necessary in this case? (Due to the simplicity of the requirement that it is not stated)
Thanks for any advice.
Cheers.

Han Ming
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

No you do want a MVC, actually you will lose points if you don't. However, in your controller you just need a reference to the GUI, and to the Data class, Observable wasn't necessary.
I actully wrap my IDataClient like interface into a Facade pattern where I only have the basic methods that the client actually needs. Search, Book Flight, and maybe fill JComboboxes.
Your actionlisteners in your GUI can accept an ActionListener to an object as in the following example

In my controller I have a method that is called assignActionListener. In that method I have anonymous inner class that will attach a method from my controller to the search button as follows

Now my search button, when clicked will call the searchFlight method in my controller.
That is just one example of the listeners that I have used.
Hope that helps. But maybe Observable will still work for you.
Mark
HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi Mark,
Thanks for the advice.
Yes, I understand what you mean.
I've thought of using a Facade pattern too, but the requirement mentioned that the DataClient must exposed the same public methods as the Data class. Thus, I have my IDataClient the same methods as Data class.
I was told in the ranch to stick strictly to the requirement.
So, I've sort of use the Facade in the ClienGUI class where in the class it has searchFlight, viewFlight and bookFlight methods and they only methods to be invoked by the GUI.
I find this not a very good design.
Maybe I'll add a Facade in between the ClientGUI and IDataClient and the Facade will act as my model too.

And, I just read on AbstractTableModel and I found it to be a very useful.
Maybe others at this stage of the project can consider as an alternative to implement your Model.
Comments.
Thanks Mark!!!

Han Ming
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on class design for DataClient and Client
 
Similar Threads
Design issues with local-remote Data class
location of DB.DB file
DataClient Adapter pattern
Design review
instruction - writing Data Client. "WAITING FOR RESPONSE"