• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MVC design issue

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ThanX for the tip with the mediator, I'll will consider it.

Regars M.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic