So let’s imagine a simple IS-A relationship like this example:
create table EntityAbstract(
IDEntityAbstract int identity primary key,
Name nvarchar(50) not null,
)
create table OneOfConcreteEntity(
EntityAbstract int,
constraint PK_Image primary key (EntityAbstract),
constraint FK_Image foreign key (EntityAbstract) references EntityAbstract(IDEntityAbstract)
)
When i’m mapping the entities from the database should i make them individual and unique objects or should i make the concrete class extending from the abstract entity?
e.g:
public class EntityAbstract
{
public int EntityAbstractID { get; set; }
public string Name { get; set; }
public EntityAbstract(int entityID, string name)
{
this.EntityAbstractID = entityID;
this.Name = name;
}
}
public class OneOfConcreatEntity : EntityAbstract
{
public OneOfConcreatEntity(int entityID, string name) : base(entityID, name){ }
}
What’s the best option? considering more than one concrete entities and more complex ones.
There are several design patterns involving an IS-A relationship, and generally this is exactly what inheritance is for.