MVC vs Netbeans Form Builder
I develop a lot of small apps where I work. As a result, I've switched from using gridbag in most p开发者_运维知识库laces to using the netbeans form builder. I sometimes use grid layout, box layout and flow layout.
I've found that instead of developing a seperate controller object that I often simply double click on the button that I want to add functionality to and then I add the call to the database adapter interface from there.
Is this wrong?
Situation:
I have a Cat class and a Cat herder class and they both exist in the database. I have a view that gets the most recent cat from the database and tells me which cat herder it belongs to.
Should this button talk to an intermediary controller or is the ActionListener that fire the ActionPerformed the controller?
I would say that depends on how much business logic your application is doing.
I have written an app exactly the way you describe. I laid out all the panels in Netbeans, and wrote SQL statements to fetch the data directly into my frame/panel classes. I double-clicked the buttons I created and any actions that needed to occur, I also wrote the code into the generated methods in my frame/panel classes.
However: This application was simply to read/write stuff from a database, display the data on the screen and allow it to be edited. There was absolutely no logic in the code, there was hardly even any validation.
If there is any kind of logic or processes which need to happen (which most apps have) then I would create objects to perform those actions, which themselves e.g. execute SQL statements or whatever. Firstly that makes the code easier to write (separation of logic and presentation) and secondly easier to re-use (e.g. two buttons on different forms which perform the same action). However, it is a more complex application design, and complexity should only be introduced if it is justified.
精彩评论