I have the following class CRUD
which is generic:
public abstract class CRUD
{
protected string tabela = null;
protected object classe = null;
public CRUD() {}
public virtual void insert() { //código }
public virtual void select() { //código }
}
I created another class whether it inherits from the CRUD
class:
public abstract class PessoaCRUD : CRUD
{
public PessoaCRUD()
{
tabela = "TBUsuarios";
classe = this;
}
//sobrescrita do metódo da classe pai
public void insert() { //código }
}
And I have my class Person who inherits from CRCR:
public class Pessoa : PessoaCRUD
{
public string Nome { get; set; }
public int Idade { get; set; }
}
And when I need to use the person class it would look something like this:
Pessoa pessoa = new Pessoa();
pessoa.Nome = "Julia";
pessoa.Idade = 23;
pessoa.Insert();
At first it is working, but I was in doubt, could make the class Pessoa
inherited from class CRUD
, however if any method needs to be overwritten it would have to be implemented in class Pessoa
, and not wanting to pollute class Pessoa
with methods related to CRUD
created class PessoaCRUD
.
Is it correct to implement like this? otherwise what would be a better approach, taking into account design patterns?