tags:

views:

93

answers:

1

I want to design an interface has the function to do mapping from Entity object to Form object


public interface 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?

+2  A: 

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

   }
}
Waleed Al-Balooshi
I guess this does not answer the question.
Gabriel Ščerbák