Applying an MVC Template to an Existing Application

This is the next question to the MVC and SWING Template . I am trying to implement an MVC pattern in an existing code snippet. Existing code creates a JFrame that acts on both the view and the controller. There is a table in JFrame, and the table model is an adapter to the user data model. Whenever a user performs an action, the model is updated by performing the following actions:

CustomDataTableModel cdtm = (CustomDataTableModel) DataTable.getModel();
CustomDataModel cdm = cdtm.getModel();
cdm.delete(1);

I tried to imagine how it works at the moment, but I also imagined how I suggest that relations with the future controller and model should be.

MVC

Now, my question is, can I continue to use the model as it is now? Can I implement the following and still stick to the MVC pattern?

  • The user selects an item in the table and clicks the delete button .
  • The view delegates the action to the controller.
  • The controller accesses the table through an accessory in the view and performs an update.
  • The model, when it is updated, notifies JTable that it has been changed.

If any other components in the view display data from the table, this can be solved by registering listeners in the JTable table model.

Update 1

MVC, . , - , , - , . , MVC - tablemodel - ?

MVC

. , , , . ( ) . , . , MVC? ? , , ? , , , , : -)

+3
2

:

, , , Action, "". .

+3

, , - .

, MVC-. ( , , ) , , ? , , , . , , MVC-, , .

:

  • . ( ).
  • , . , , .
  • , , .
  • (), , .
  • , .

, 4, , . ( , , ).

, "" - , . , , , .

, - . ( , unit test), .

, .

+2

All Articles