开发者

design the interface

开发者 https://www.devze.com 2022-12-28 16:26 出处:网络
I want to design an interface has the function to do mapping from Entity object to Form object public interf开发者_开发百科ace IFormToEntityMapper

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

精彩评论

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