I’m making a program in which I have a list of items. You can add a new item or you can edit an existing one. The dialog window for editing an item and adding a new one is practically the same, one small detail that changes is that well, one edits and the other one adds the item, very little else is different.
I was wondering if it’s generally a better design choice to have two separate classes or to have only one class to which a parameter is passed that specifies whether the dialog is for editing or for adding.
I’m using C++ with Qt but I think the same design choice would apply to any OOP language/framework.
Thanks in advance.
I usually use the same MVC classes for both CREATE and EDIT mode. The model holds a flag to indicate which mode. The View would read the flag in the Model to determine which controls to be displayed/enabled etc. The Controller would also read the flag on the Model to determine which service layer method to call when the user submits the form (e.g. update or create).
I find that this is a more maintainable solution because it avoids duplication and it keeps the logic in one place. i.e. view logic in one view as opposed to two, controller logic in one controller as opposed to two….