开发者

design the interface

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) {

   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜