I am developing a simple form creation mechanism in which users can create new forms using various types of template fields (Date, Text, DropDown)
I decided to model the domain object (form field) regardless of the objects that will be used to visualize these fields in the user interface.
Here is the interface that defines the contract for the domain and some of its specializations:
namespace Acme.Core.Domain{
public interface IFormField
{
bool Visible { get; set; }
string Key { get; set; }
event EventHandler<FieldVisibilityChangedEventArgs> VisibilityChanged;
FieldType Type{get;}
void Validate(IEnumerable<ValidationError> errors);
int DataId {get;set;}
}
public interface IDropDownField:IFormField{
IDictionary<string, string> Items { get; set; }
KeyValuePair<string, string> SelectedValue { get; set; }
}
public interface IDateField:IFormField{
DateTime? SelectedDate{get;set}
}
}
For the user interface side, I built a parallel type hierarchy. This saves the domain object that is associated with business rules around data validation, separate from user interface problems, namely how to visualize this field (MVC HtmlHelper vs WebForm WebControl):
namespace Acme.UI{
public interface IControl
{
bool Visible { get; set; }
string ID { get; set; }
}
public interface IDropListControl:IControl
{
}
public interface IDatePickerControl: IControl
{
}
public interface IControlFactory {
IControl CreateControl(IFormField field);
}
}
, . , , , . , ?
EDIT: UI - (Core.csproj). , . , , .
public interface IControlFactory {
IControl CreateControl(IFormField field);
}
public interface IFormFieldDataBinder{
void Bind(IFormField field, IControl control);
}