I implemented an abstract% class with Service
and another using Generics
being concrete.
Every design structure for each concrete class has an abstract.
My doubt seeing the following ...
When using the reference EmpresaService
, it points to the method in the abstract class and not the concrete, and this is bad because it complicates when implementing individual methods in class this.Dao.ExisteRegistro();
for example.
Is my error being in class design?
PlanoService class
using System;
using System.Collections.Generic;
using Cobranca.pkgDao;
using Cobranca.pkgModel;
namespace Cobranca.pkgService
{
public class PlanoService : Service<Plano>
{
public PlanoService()
{
this.Dao = new PlanoDao();
}
//método em questão que mostra o erro
public bool ExisteRegistro()
{
return this.Dao.ExisteRegistro();
}
// métodos e mais métodos abaixo
}
}
Class EnterpriseDao
using System;
using System.Collections.Generic;
using Cobranca.pkgModel;
using MySql.Data.MySqlClient;
namespace Cobranca.pkgDao
{
class EmpresaDao : Dao<Empresa>
{
public bool ExistePlanos()
{
try
{
base.AbrirConexao();
MySqlCommand cmd = base.Conexao.CreateCommand();
cmd.CommandText = "SELECT COUNT(*) FROM planos";
return Convert.ToInt32(cmd.ExecuteScalar()) > 0;
}
finally
{
base.FecharConexao();
}
}
}
}
Dao class
using System;
using MySql.Data.MySqlClient;
using Cobranca.pkgModel;
using System.Collections.Generic;
namespace Cobranca.pkgDao
{
public abstract class Dao<TModel> where TModel : Persistant
{
public abstract bool Inserir(TModel model);
public abstract bool Editar(TModel model);
public abstract bool Excluir(long codigo);
public abstract List<TModel> CarregarDados();
}
}
Classe PlanoDao
using System;
using System.Collections.Generic;
using MySql.Data.MySqlClient;
using Cobranca.pkgModel;
namespace Cobranca.pkgDao
{
public class PlanoDao : Dao<Plano>
{
public bool ExisteRegistro()
{
try
{
base.AbrirConexao();
MySqlCommand cmd = base.Conexao.CreateCommand();
cmd.CommandText = "SELECT COUNT(*) FROM planos";
return Convert.ToInt32(cmd.ExecuteScalar()) == 1;
}
finally
{
base.FecharConexao();
}
}
}
}