wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes MVC design issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "MVC design issue" Watch "MVC design issue" New topic
Author

MVC design issue

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, people

I think I need some advice regarding to this issue:
My UI contains a JTable used to display available and unavailable records.
The user can select one row (record) and book it.
But not all the records are "bookable" (because of 48H/time rule) so the UI must react different on available or unavailable records.

I place this logic on controller.
So if the view tries to book a record first it informs the controller about and the controller decides if the record can be booked or not.
If the the controller decides that the record is bookable it starts the book UI (for the customer ids) and after this it informs the Model.

Is this OK ? or I push the MVC pattern to far.


Any help will be appreciated
ThanX very much


SCJP, SCJD, SCWCD, OCPJBCD
Thirumurugan Mylrajan
Ranch Hand

Joined: Jan 26, 2006
Posts: 64
Hi,

I did things more or less the way you mentioned except that I did not worry about implementing Design Patterns!!..

In the Client I validate whether a record chosen by user is bookable( everything, including 48 rule) and then call the worker thread to do DB updates. After it completes it calls back another method in EDT which will update the table.

I feel that design patterns are good, but a good solution is more important than the patterns themselves..

Hope this helps.

Thanks.


SCJP , SCJD. (IBM 142 in progress).
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, Thirumurugan

Thanks for your answer.
I am not shore that I understand wat you mean.
Can you detaliate a little

ThanX M.
Thirumurugan Mylrajan
Ranch Hand

Joined: Jan 26, 2006
Posts: 64
Originally posted by Mihai Radulescu:
Hi, Thirumurugan

Thanks for your answer.
I am not shore that I understand wat you mean.
Can you detaliate a little

ThanX M.


ok so here is how I do my booking..

1. Assuming the results of the search are already displayed on the JTable
2. Get the details of the selected row and validate them (Like customer field blank, date validation, 48 hr rule )
3. If its ok throw a dialog to the user asking him to enter the details, like start date, cust id.
4. It user is ok and presses a button do a validation and if its ok, create a thread for back end updates.
5. The backend check locks record, reads again to see if has not been modified and if not modified do the update.
6. On success or failure it calls another method which runs in Event dispatcher thread to do GUI updates with success, failure message, Table updation..etc

Hope this is clear.

Thanks.
[ July 16, 2006: Message edited by: Thirumurugan Mylrajan ]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, Thirumurugan

I understand - I have a similar workflow, but how create the customer id dialog? The view or the controller ?

Regads M.
[ July 17, 2006: Message edited by: Mihai Radulescu ]
Thirumurugan Mylrajan
Ranch Hand

Joined: Jan 26, 2006
Posts: 64
Originally posted by Mihai Radulescu:

I understand - I have a similar workflow, but how create the customer id dialog? The view or the controller ?

[ July 17, 2006: Message edited by: Mihai Radulescu ][/QB]


I did not think in terms of the Model-view-controller pattern. Let me try it..

The model in this case is the TableModel. View is the JTable and the controller is the background thread which updates the model.

I cannot create a GUI from a background thread since its not in EDT.

So I throw the dialog from the code which does the inital validation of the data shown in the JTable. So I think in my case the dialog is thrown from the view. But strictly speaking its not from the view, but from an instance holding the view.

Thanks.
Robert Bar
Ranch Hand

Joined: Jun 29, 2006
Posts: 38
hi,

very interesting discussion about MVC paradigm (IMO: it's not a pattern) can be found here:

c2 wiki

Derivations & extensions to MVC are everywhere, and it's really hard to say what acts as a view/controller/model in certain solution. For example, JavaSwing is described as using the Model-Delegate pattern, which is a is a variation of the MVC. TableUI is a view-controller part, and JTable acts as a model (because holds all data selection index, column names, values, etc.)

So, don't worry about MVC, it's already in your implementation, both in micro- and macro- scale!

To simplify interactions between gui components I prefer to use mediator pattern. It really helps in situations, where it's necessary to do many things (like changing state of many components - enabling, selecting, resizing, blocking input) at the same time. For example:

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

ThanX for the tip with the mediator, I'll will consider it.

Regars M.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC design issue