• 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

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just curious

Lets say I got 3 different type of view A, B, C.

Does it means I will have 3 Views, 3 Controller and 1 model?

or each view has its own model.

if each view has its own model.. how do I control each of the model?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends. These 3 views could have the same controller, but could also have a different controller.
 
Ixus See
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but what about Model?

Must I have only 1 Model?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on your situations. For a book application you'll have a view to display all books, update a book, delete a book, view the details of a book and create a new book. So you'll have 5 views, 1 controller and 1 model. More info on MVC can be found in a design patterns book and on the internet (e.g. here). A design pattern usually comes in many, many flavors.

 
Ixus See
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after a smoke break...(haven't smoke for years)

I finally come out with a design.. I am going to have a panel with menuTab..

there will be 3 menu tab..

1) search tab .. able to view all, search, delete, enable edit tab go there.
2) create tab.. create new record
3) edit tab

1 model 1 view controller

....

--------------------------------------------------------------------------

just curious do i need a UI to allow the user to choose between server, standalone, UI with network?
 
Ranch Hand
Posts: 170
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
keep in mind that only searching and booking should be available as per spec...

The user interface for this assignment must satisfy the following criteria:
• It must be composed exclusively with components from the Java Foundation Classes (Swing components).
• It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.
• It must present search results in a JTable.
• It must allow the user to book a selected record, updating the database file accordingly.
 
Ixus See
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jonathan Elkharrat wrote:keep in mind that only searching and booking should be available as per spec...



that means my UI will be

1) .. able to view all, search, delete,

that make my work much easier
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And could you please stop quoting complete posts. This has no added value at all, certainly not when just 2 people are discussing in the same topic.

I don't like your UI design. Much too complicated.

The parameter used at startup ("alone", "server", <nothing>) specifies which application should run (according to your instructions). Of course you need to provide the user a little UI so he/she can enter the necessary configuration settings (ip, port, db location) depending on the mode the application is running in.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ixus See,
Your post was moved to a new topic.
 
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:So you'll have 5 views, 1 controller and 1 model.



For this assignment you have only one view - your application that displays records. If you had a web interface (like Andrew Monkhouse implemented) then that would be a second view. If you implemented a mobile web application, then that would be a third view. That is the commonly understood use of the term View in the MVC pattern.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean Keane wrote:That is the commonly understood use of the term View in the MVC pattern.


You can have multiple views based on the same model within the same technology (as described here). A view just renders the contents of a model. It's just a representation of the model data and thus when the model data changes, the view must update its presentation. Nothing's said about needing another technology.
 
Sean Keane
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:

Sean Keane wrote:That is the commonly understood use of the term View in the MVC pattern.


You can have multiple views based on the same model within the same technology (as described here). A view just renders the contents of a model. It's just a representation of the model data and thus when the model data changes, the view must update its presentation. Nothing's said about needing another technology.



I think you've misunderstood the main point of my post. The main point was this assignment will not have five views as you mentioned. It will have one single view - i.e. the user interface that you develop.

My examples just happened to be different technologies. They could have all used the same technology. You seem to have mistakenly interpreted this as me saying each view must have a different technology. Which I never said
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean Keane wrote:My examples just happened to be different technologies. They could have all used the same technology. You seem to have mistakenly interpreted this as me saying each view must have a different technology. Which I never said


True, You didn't say it directly, but the examples you gave could insinuate different views can only happen with different technologies.

My example was also not suitable for the assignment, although you have 1 view with the table (to show all matching records). Would a dialog with the detailed information of a room (when you double click on a record in the table) be considered as a 2nd view?

I'll give another clear example from the Eclipse IDE. For a HTML file you can show your html file in source mode (just the source of your html), visual design mode (a wysiwyg editor), a split-screen source/design mode (the 2 previous modes combined) and a preview mode (how will your html page look in IE and/or Firefox). Each of these modes is a different view. All these views are based on the same model (your html page). When you make a change to one of these views, the model changes and the other views update their representation.
 
Sean Keane
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They were just examples. I could have given examples all with the same technology. Giving examples in different domains highlights the concept of a view. I think you just misinterpreted it

Whether a dialog showing the room information is considered a separate view is debatable. But I think we are getting away from the main point of the original poster. I was simply highlighting the concept of a View in the MVC pattern, as the original poster would have been mislead if they thought that this assignment had five views.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean Keane wrote:I was simply highlighting the concept of a View in the MVC pattern, as the original poster would have been mislead if they thought that this assignment had five views.


And what do you think I did with your example? Exactly the same: preventing the OP possibly could misinterprete your example (as I did too)
 
Sean Keane
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The difference is that stating the assignment has five views is incorrect. Whereas my examples were not incorrect - all of my examples were correct descriptions of different views when using the MVC design pattern.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean Keane wrote:The difference is that stating the assignment has five views is incorrect.


I never stated that
 
Sean Keane
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, you were talking about a book application! It is still misleading to describe things in terms of a book application, saying that deleting a record is a separate view in the MVC design pattern - it's not a separate view, it's just an operation you can carry out on the single view that you have.

Anyway, let's leave book applications to one side, for this assignment it is quite simple - you have one view
 
Ixus See
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More question on MVC

My implementation of MVC

View implements observer- register all the button with an actionlistener and action listener call controller's method
Controller - contain methods which call the model.
Model extends Observable - contain all the logic methods calling DAO


Here are my questions:

1) Lets says I click exit button. can my action listener just open a JOption box with yes no and quit... (without calling controller) ?

2) Lets says I click View all Record ... should my implementation be

a) actionlistener -> controller -> model -> getAllRecords -> model.getRecords and model.setViewJTable without calling notifyObservers

b) actioner listener call model.getAllRecords directly and returns a set of records and set the JTable

c) other implemenation


3) Lets say a record is already book or deleted.. should the business of checking be in DAO or Model?

4) What is the best way to differentiate the different method that call notifyObservers in model? for example if someone updated a record and the record change should flow back to view.

How is this achieve and differentiated from a delete record command and JTable should remove it if it has it on the list.

5) Lets say client A update the record, therefore client B should show the change too if it exist on the JTable. How is this achieve? I don't understand how 2 clients on 2 different computer can be notify in such cases.

Sorry for the list of questions...
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1/ I didn't show an extra JOption box, but I think it's fine showing it from the ActionListener

2/ In my application I have following flow: click the search button, controller-method is called, the controller makes a call to the model (the business service) and this service calls the find-method in Data class. The matching records are returned and are turned into a TableModel which is handed over to the JTable.

3/ My business service executes a number of business rule validations (e.g. room already booked). I decided to keep my Data class unaware of the type of data it's processing. So my Data class can easily be used to handle a similar database file containing customers or hotels or ...

4/ When a record is updated (with a customer id) the JTable is updated again with executing the search again with exactly the same filter. I didn't allow deleting records in my GUI, but I would implement it just like that again.

5/ I didn't implement a mechanism to push changes to different clients.
 
Sean Keane
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:4/ When a record is updated (with a customer id) the JTable is updated again with executing the search again with exactly the same filter. I didn't allow deleting records in my GUI, but I would implement it just like that again.



Does this mean that when a client books a room in your application you submit a search request from the client? If so, what is the point of this? Could you not simply update the information locally in the application? I'm guessing you had a good reason why you couldn't just update the information locally - so wondering what it was?

When you book a room one of two things will happen (A) the room is booked successfully or (B) The room will not be booked because either something has gone wrong or the room is not available.

If the room was successfully booked then you could just update this information locally in the application?

If the room was not successfully booked then I guess a few things could have happened, (1) The room is already booked (2) The room has been deleted (3) Some error has occurred in the application.

So I guess you do a search after an attempt to book a room because of (1) and (2) i.e. the information currently being displayed to the user is out of date. So you redo their previous search so that the most up to date information is displayed.

Have I figured it out correctly ?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could simply update the client, but that would require some extra code. I just decided to renew the data in the table by executing the search again. That requires no extra code, because all the code needed to do this was already available. So that's less code and less code means less to maintain and less (chances for) bugs
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic