Suppose we have a abstract class EntityBase which is the base class for all our entities e.g.
public abstract class EntityBase {
public Guid Id {get;set;}
}
public class Customer : EntityBase {
public string Name {get;set;}
}
public class Orders : EntityBase {
public string OrderNumber {get;set;}
}
Where the intent is to then be able to create extension method on EntityBase so it can be projected to Domain classes e.g.
public static class ProjectionExtensions {
public static TProjection ProjectAs<TProjection>(this EntityBase item) where TProjection : class, new() {
return Mapper.Map<object, TProjection>(item);
}
}
Does this violate LSP? Is it better to implement an interface IEntity
rather than an abstract base class EntityBase
?
e.g.
public interface IEntity {
public Guid Id {get;set;}
}
public class Customer : IEntity {
public Guid Id {get;set;}
public string Name {get;set;}
}
public class Orders : IEntity {
public Guid Id {get;set;}
public string OrderNumber {get;set;}
}
public static class ProjectionExtensions {
public static TProjection ProjectAs<TProjection>(this IEntity item) where TProjection : class, new() {
return Mapper.Map<object, TProjection>(item);
}
}
IEntity
asclass
instead ofinterface