design patterns - Is it okay to break LSP for the sake of binding? -
something tells me might lynched asking this. , sorry long winded description in advance.
i'm working on of corner case in silverlight 4 project. i'm building custom form builder.
a form may have several fields may of different types (text, integer, email etc...). now, of these types extend field
class might have additional properties length in case of text field.
i have ability add , remove fields collection of fieldviewmodels
in formfieldsmanagementviewmodel
. it's pretty standard stuff far.
now,... in order user set properties against field objects have usercontrol
has dependency properties of type datatemplate
, represent ui want dipsplay when particular type of field selected. , clarify, usercontrol
has singlelinetexttemplate
property shown when singlelinetextfieldviewmodel
selected when emailfieldviewmodel
selected, emailfieldtemplate
shown. both singlelinetextfieldviewmodel
, emailfieldviewmodel
inherit fieldviewmodel
.
my issue arises when declare bindings in each of these templates. it's quite valid (imho) set properties of base class fieldviewmodel
isrequired
, position
have bindings length
in singlelinetexttemplate
match length property of singlelinetextfieldviewmodel
. i'm relying on extended interface of concrete class rather fieldviewmodel
class.
i should point out, before carry on this works. wasn't sure , does, i'm not sure should,..or should doing this.
i'm doing sake of binding , in absence of binding dynamic objects and/or lack of datatemplateselector
in silverlight.
clearly, singlelinetextfieldviewmodel
not substitutable it's base class in binding scenario. question is, since i'm not consuming these objects in code, in markup,..is still considered bad practice?
lots of in advance.
i wouldn't have problem - have done same or similar in past.
assuming use singlelinetexttemplate
when datacontext
instance of singlelinetextfieldviewmodel
(presumably through mapping datatemplate
type) there never problem, , because of resilient nature of binding framework not going have significant negative effects if try use template inappropriate type.
Comments
Post a Comment