• 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

Mark,Max,Eugene et al please help with a review of MVC

 
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The application has the following Views - SearchFlightsView,SelectFlightView, BookFlightView .
Each View has an intent/ several intents and these are made known as and when, as requests to the Controller/Controllers.
Hence SearchFlightController, SelectFlightController, BookFlightController.
Respective Controllers sends the requested Models; SearchFlightModel , SelectFlightModel,
BookFlightModel back to the View.
The View does not care how the Controller fulfils the request , therefore has no contract with any Models. The View has the "Hook" methods Mark has mentioned that the Controller listens for.
Would it be alright to have separate Controllers for each View ? Makes it more decoupled, and reusable for other applications.
As far as packaging, I plan to have
FBNClient
----SearchFlight
---------SearchFlightView
---------SearchFlightController
---------SearchFlightModel
----BookFlight
etc etc
regards
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still trying to get a handle on my own implementation of MVC. If you would share your reasons for the design you described I'd greatly appreciate it.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My main concern here would be why you have three seperate views and three seperate controllers. I don't think this application needs that many and adds complexity.
I had one view and one controller. The model was the TableModel and the DataAccessFacade. There was a popup window that displays the success or failure of the booking, and that is done using the JOptionPane, so no need for controller for that screen.
Can you discuss why you chose to have three of each?
Mark
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christian,
Yes, I've seen your own struggle with it,
hence I decided to start a new thread rather than hijack yours.
Well ,here goes.
SearchFlight and SelectFlight are potentially re-usable across several other applications that FBN may have, therefore I decided to go with a MVC design of the GUI.
The alternative would be to have BookFlight which incorporated Search and Select Flight functions. No re-usability catered for with this option.
I may even bundle Search and Select Flight together . It does not make sense to have one functionality without the other.
Book Flight View registers it's intent with the Book Flight Controller . A flight selected from the table is one against which a booking is requested.
For the actual booking , Book Flight View registers it's intent with Book Flight Controller again, and the Controller makes up the BookFlightModel via the Data Facade) and passes it to the Book Flight View.
BookFlightModel is just an array of flight Info, pre-booking and post-booking.
i still have to translate this to code (again!)
so it might be far from the mark.
MORE COMMENTS PLEASE?

[ January 24, 2003: Message edited by: HS Thomas ]
 
Christian Garcia
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you manage each of the controllers? Is there an instance of each created when the main class is loaded?
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
quoted by Mark Spritzler:

The model was the TableModel and the DataAccessFacade.


Well searching past posts , some didn't agree with choosing TableModel as the model. In this case I agree with them. This may be limiting your design to just the task in hand.
Search and Select Flight are potentially re-usable views.
Take an example of a text-field.
The actual text-field is the view.(An event source).
This text-field may allow several actions
- input , automatic setting depending on some other selection etc.
These actions generate events that the text-field controller handle. A controller can be thought to be an action listener.
I've just extrapolated this example.
So my Search & Select Flight is a series of Text boxes (Search) and the JTable(from which a flight is Selected).(yes I think I've decided to bundle them into one. Mark , this reduces some of the complexity).
Searching on different criteria (action) generates an event. A listener for the event (controller) gets the model and pops it into the JTable (view).
Selecting a flight from the table generates an event which the BookFlightController listens out for and pops the details in the BookFlight View ( a Dialogue Box)


How do you manage each of the controllers? Is there an instance of each created when the main class is loaded?


Christian,
I haven't started coding yet , I'm just surmising at the moment. I may need to look to Swing API for inspiration.
If I find myself using a predefined action listener that simply delegates action handling to another listener perhaps I'll stop going down this route.
Any more input welcome.
[ January 25, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
I've cut it down to 2 models and 2 Controllers.
But I'd still like to make Search & Select Flight re-usable for other applications.
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas,
Don't go for more than one view and one controller. I did the mistake in my submission and lost over 8 points in GUI. I had 3 views and 3 controllers. Keep in simple with hook methods, one view and one controller. I can only tell you that you will get full score in GUI if you keep it simple with one view and one controller.
-- Sai
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sai,
Once again, I 'll let experience guide me .
So, one View and Controller it is.
Thanks Sai,Mark.
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I think there are a lot of valid ways to do this. However, I generally agree with Mark. Keep it to a single view/controller. However, if that doesn't seem right to you, then you might consider three views, one controller.

What's that you say? Madness?
Not at all. A single controller, with three interfaces, one for each view, might just be the ticket for you. It's essentially not different then a single view with a single controller, except that it allows you to 'sub divide' your single, larger view into three smaller logical units.
Just a thought,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
[ January 25, 2003: Message edited by: Max Habibi ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Max,
Thanks for your guidance , which was very welcome.
Using the any number of views - 1 controller approach where is the advantage apart from
being able to logically separate your views ?
Do you see just the view part being usable in other applications ( in my example Search and Select Flight " )?
Having just one controller per Application , another application would have to re-write the listeners (for the very same events). I think there is a potential for re-use here that is not exploited.
Also to my thinking Search and Select Flight will more than likely ever have one Model.
A Container for flight info.
Again a potential for re-use here .
I've once again taken on board the point about keeping things simple as far as the assignment goes which I'll follow. ('cos I want to pass!).
But any tips for the future will be very welcome.
Point out some Patterns , give some examples, hints on packaging ?
Thanks again.
regards
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
quoted by me:

Also to my thinking Search and Select Flight will more than likely ever have one Model.
A Container for flight info.
Again a potential for re-use here .


I am trying to pin down a good definition of model.
Any help with this would be appreciated.
Is Container too limiting?
regards
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Model I think of as "Data". or sometimes the class that has access to Data. So I include, sort of, my DataAccessFacade. For instance My controller to get data to pass to the GUI it calls a method on the DataAccessFacade, which returns the data and gives it to the Controller. The inheritence of DefaultTableModel is a model too of course.
Mark
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I'm a little scared if I read your posts. I also designed my gui as 3 mvc "classes":
- Overview: Controller, View, Model
- Book: Controller, View, Model
- Search: Controller, View, Model
Is this design really penalized? As I understand the design should also be design for future enhencemend.
Your user interface should be designed with the expectation of future functionality enhancements, and it should establish a control scheme that will support this with minimal disruption to the users when this occurs.
So, please tell my if I should rewrite my client.
Pascal
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by pascal auderset:
Hi all
I'm a little scared if I read your posts. I also designed my gui as 3 mvc "classes":
- Overview: Controller, View, Model
- Book: Controller, View, Model
- Search: Controller, View, Model
Is this design really penalized? As I understand the design should also be design for future enhencemend.
Pascal


Well, yes and no. Yes, you've taken a somewhat unconventional approach, so your grader is going to have to work a little harder to figure out what you did, so they'll be in a slightly worse mood, so they might 'penalize' you a bit.
Or maybe not.
Either way, however, your most important job is to have a simple approach. Have you done so? Were you able to give your code to your friends, and have them figure out what you did by just looking at it? If so, you're probably ok. If not, you might want to reconsider.
All best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark ,
I prefer your definition.
Data has a nice depth to it when describing the Model. Container wasn't right at all, was it ?I've come across other definitions like business logic , core functionality.
But that's very difficult to design programmatically.
Borrowing from that other thread on MVC running in parallel, I think I'll stick with FlightModel,
- covers a few angles.
Can this and the DataAccessFacade be one and the same ? Hmmm. One Model is beginning to sound like a good idea.
In fact, Max's suggestion of 3 Views and 1 model , 1 Controller is very feasible .
Search, Select and Book/ Reserve are potentially re-usable functions for many Models.
Having the same Look and Feel for a given Model for each of these functions across applications can only be a good thing and this can be achieved by having a re-usable view for each.
Actually , I am going to back-track on the last one, unless someone tells me other-wise.
Same Look and Feel and the MVC paradigm don't fit together very well. It will be the designer's choice to re-use a View for a given Model in another application . (we could make it easier for them, though,if needed)

1 Model, 1 Controller , 1 View as far as the assignment goes, rules the day.
Max,
thanks for the cautionary though not directive note. (You're right I could split the Views to logically separate them. Makes it easier to follow the code but I'm not going to try the re-use argument again).
Hope I am not confusing anyone else ?
[ January 28, 2003: Message edited by: HS Thomas ]
[ January 28, 2003: Message edited by: HS Thomas ]
[ January 28, 2003: Message edited by: HS Thomas ]
[ January 30, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just starting to code this, and I wondered whether anyone found it useful to break MVC down into individual patterns as given here.MVC
I think it may help some people.
I am somewhat familiar with Composite, ObserverObservable,
Mediator/Facade but not with Strategy.
regards
[ January 30, 2003: Message edited by: HS Thomas ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic