2

I have an MVC app, which has multiple views that give overviews (from different angles) on items.

For now, let's just call these views

  • View1
  • View2
  • ...
  • ViewX

They all use the same Model Collection as a basis

As of now I have one controller per view (View1Controller, View2Controller, ...), and furthermore, I have ItemEditView and ItemEditController for the item edit window.

When certain interactions occur inside the numbered views, the same actions have to be done:

  • Action Chain 1: Boil down the clicked position/button to two values, check whether these two values allow to make a new item, if so, open the ItemEditView to create a new item.
  • Action Chain 2: Check whether this item may be shown, if so, open ItemEditView to edit the item.
  • Action Chain 3: Check whether this item may be changed, if so, update it based on the position it was dragged to.

How would I best split this into functions and controllers?

As of now, the function View2Controller.ItemClicked() calculates some additional parameters required by View1Controller, and then calls View1Controller.ItemClicked()... I guess this is a terrible mess, but where would I put common functions of all ViewXControllers?

Or should I put all functions of all the Views into a common controller?

1
  • View2Controller extends View1Controller maybe
    – null
    Commented Jun 20, 2015 at 12:51

1 Answer 1

1

If I understand this correctly, you are describing a composition rather than distinct views.

  1. There is a item which can be clicked and which opens a edit view.
  2. There is a view which contains the item and decides if editing of the item is allowed.
  3. There is a view which contains the item and performs model modifications without opening a edit view.

I don't know if the framework you work with allows this kind of composition, but this is how I would design this: The item itself consists of a view and controller and handles the clicking and opening a edit view. The second view enables/disables the item based on rules if the item may be edited. The third view disables editing for the item and only uses it for displaying data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.