JohnQ
JohnQ

Reputation: 1093

MVC Architecture and Modal Dialog Windows

I am developing a project in a MVC architecture. It should be a simple application to manage some customers.

There are MainModel, MainView and MainController classes which make the main window to show the content of the customers tables and to let the user insert, remove or edit customers.

My problem is that the insert and edit buttons should show some dialog windows to let the user insert and edit some text values and I have some doubts.

I would like to ask you some questions:

Thank you very much.

Upvotes: 3

Views: 1860

Answers (2)

trashgod
trashgod

Reputation: 205785

Irrespective of modality, you can use the observer pattern to keep your dialogs synchronized with the application's model. This example uses a PropertyChangeListener; other approaches are mentioned here.

Upvotes: 2

kwikness
kwikness

Reputation: 1445

Although I can't fully tell from your post, I'm not sure you're thinking of MVC the right way. But let's say you have a Customer, CustomerView, and CustomerController class..

Customer could contain all of the business logic related to being a customer-- so it might have methods like setBalance(int newBalance), getBalance(), etc.

The CustomerView class could essentially be a subclass of JPanel or JFrame (since it looks like you're using Swing from your question's tags). This class would be representative of one Customer instance. Maybe you could have a private Customer class variable. This class's responsibilities should only consist of displaying the data to the user contained in its Customer instance as well as allowing them to modify it.

It would be tough to say what the CustomerController would do since I don't know anything about your application, but it could potentially contain ActionListeners and that sort of thing that help to route input and output to the different parts of your model and view.

I did some googling and found a pretty straightforward example you may want to check out: http://www.austintek.com/mvc/

Good luck. Hope this helps.

Upvotes: 0

Related Questions