Elad Nadav
Elad Nadav

Reputation: 27

implementing MVC design pattern for the first time with Swing

This is somewhat a theoretical question. I'm trying to write my first application with MVC design pattern in mind.

The app is a memo writing app. As this is the first time trying to apply this design pattern I would appreciate some feedback on how to plan my project.

In my model part I plan to have a hash map as the data structure with the date being the key and the memo being the value. so I'll have a Date class and a Memo class and a Model class with the hash map that will interact with the other 2 classes.

In the view part I'm planning 3 combo boxes for the date following with a button to show existing memos for that date or an empty text area for adding a memo and a save button. I though of having one class that extends JFrame with the rest of the components inside.

The controller part is where I get stuck. how do I go about it? I'm use to having the view part dealing with the data on it's own. Another tip I got was to separate the different parts with interfaces but I'm not sure how exactly.

Lastly, where do I put the Listeners for the buttons in the frame class or in the controller?

Any insights or feedback would be greatly appreciated.

Upvotes: 0

Views: 40

Answers (1)

Yair Frid
Yair Frid

Reputation: 11

In MVC, while the user sees the view, it actually uses the controller. which basically means that input should be sent to the controller and from there it should be manipulated and updated where needed in the data. In your case it means that the button listeners input(click) should be sent to the controller, e.g the controller should listen to the click.

on another note, why use HashMap where you can use plain old java objects? they will be more extensible eventually when you want to add more features.

Upvotes: 1

Related Questions