Is it better to have one class for a new element dialog, an editing dialog, or different classes?

I am making a program in which I have a list of items. You can add a new item or edit an existing one. The dialog box for editing an element and adding a new one is practically the same, one small detail that changes is good, one editing, and the other adds the element, and another completely different.

I was wondering if, in general, the best design choice should have two separate classes or only have one class that is passed a parameter that indicates whether the dialog will be for editing or for adding.

I use C ++ with Qt, but I think the same design will apply to any OOP language / structure.

Thanks in advance.

+3
source share
3 answers

I usually use the same MVC classes for CREATE and EDIT mode. The model contains a flag indicating which mode. A flag in the model will be displayed in the view to determine which controls should be displayed / enabled, etc. The controller will also read the flag on the model to determine which service level method should be called when the user submits the form (for example, update or creation),

I find this a more convenient solution because it avoids duplication and keeps the logic in one place. that is, the viewing logic in one view, unlike two, the controller logic in one controller, not two ....

+2
source

( "" MVC - HTML XML). Qt, , , .

, , 3 :

  • " "

- # 1 # 2.

+2

. , . . , OK/, UNDO.

0

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


All Articles