oop - MVC one or separate models? -
i'm working on web site has 2 different possibilities client support. in both of them required submit small form of needed fields.
i implemented 1 of them using pretty basic model containing necessary properties name, email , couple of others more, user enters his/hers data, , if fields valid, redirected screen congratulates him on successful submission of form.
the second 1 requires same input client first one, except 1 field not included, , there other fields client must fill in order second type of support.
i wondering idea use same model both views although neither won't use of properties, since creating 2 distinct models half same properties seems waste me.
use inheritance models:
let's say, input 1 requires properties a
, b
, c
. input 2 requires b
, c
, d
.
create 2 classes:
public abstract class mythingybase { public int b { get; set; } public int c { get; set; } } public class input1 : mythingybase { public int { get; set; } } public class input2 : mythingybase { public int d { get; set; } }
this way both classes have properties need without code duplication. can share handling code b
, c
placing in works mythingybase
class.
Comments
Post a Comment