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.
Joined: Oct 18, 2001
Opps, sorry that the figure looks distorted as the white spaces is removed. It should look better this time
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.
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
Joined: Oct 18, 2001
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!!!
subject: Question on class design for DataClient and Client