c# - Violating polymorphism by having base ViewModel class determine current type? -
i have base viewmodel has public method. things pretty simple @ first , role same of derived classes, want viewmodel different things depending on derived class calls it.
so example have:
public void domethod() { dothismethod(); }
we want like
public void domethod() { if (this.gettype().name == "thisname") dothismethod(); else doanothermethod(); }
is wrong this?
yes, solution propose wrong design point of view. base class should agnostic of inherited type "thisname". using naming resolve problem implementing in way:
public class viewmodel { public virtual void domethod() { doanothermethod(); } public void doanothermethod() {...} } public class thisname: viewmodel { public override void domethod() { dothismethod(); } public void dothismethod() {...} }
Comments
Post a Comment