How to make the controller change its behavior depending on the type?

If a user enters some invalid data from one view, for example:

    Email: bill@apple.com    

then I want the controller:

  • do not put data in the model
  • reddish color text box
  • does not allow the user to save

But it is possible that if the user enters the same invalid data in a different view, I want the controller:

  • place the data in the model
  • reddish color text box
  • allow user to save

But it is possible that if the user enters the same invalid data in a different view, I want the controller:

  • place the data in the model
  • color text box bluish
  • allow user to save

And it is possible that another view would be:

  • place the data in the model

, :

  • ,

:

  • ,

[ad infinitum]

n- n-views, ?


Update

stackoverflow, " ". , , .

:

  • , , .

  • . , .

  • . , truncated exception

MVC, //, - , .

+3
3

, , -. - = > .

, , , , , , , , .. ?

.

acceptsInvalidData => boolean, place invalid data to model
requiresAutoCorrection => boolean, auto-correct the data
synchronizeWithModel => boolean, always keep the view in sync with the model
allowsSavingInvalidData => boolean, allow saving of invalid data
invalidDataIndicator => string:color, how to color view for invalid data

5 (, ), , . .

+1

, , imho. . - , , , - , , , , , . . .

+1

:

  • , N N .

  • ( 1 โ†” 1), controller, .

:

  • , , N N .

  • A B ( 1 โ†” 1), B, A.

2 :

  • MVC, : N , N , , (, ) N / .: -)

  • MVC, . MVC M, V C, (, ). , . , ( N ), C V (, 1 1 - -).

Of course, MVCmuch success was achieved in decoupling Ms from Vs and Cs, but less success in decoupling Vs and Cs from each other. I think that currently sensitive interfaces require a combination of views and controllers or start differently, itโ€™s not worth the effort and complexity to strongly isolate views and controllers. This modified approach M(VC)worked much better for me in the real world.

0
source

Source: https://habr.com/ru/post/1737398/


All Articles