I want to design an interface has the function to do mapping from Entity object to Form object
public interf开发者_开发百科ace IFormToEntityMapper { TEntity Map(TForm tForm); }
and vice versa.
public interface IEntityToFormMapper { TForm Map(TEntity tEntity); }
I have the question if I should define these two functions in one interface and separate them to different interfaces. If I put them into one interface, does that violate the single responsibility principle?
One option is to use Generics for the Interface:
public interface IMapper<TSource, TDestination> {
public TDestination Map(TSource source);
}
public class FormToEnityMap : IMapper<Form, Entity> {
public Entity Map(Form source){
}
}
public class EntityToFormMap : IMapper<Entity, Form> {
public Form Map(Entity source) {
}
}
精彩评论