-1
I implemented a class Service
abstract using Generics
and another using EmpresaService
being concrete.
Every project structure for every concrete class has an abstract.
My doubt seeing from the following...
When using the reference this.Dao.ExisteRegistro();
, it points to the method in the abstract class and not in the concrete class, and this is bad because it complicates when implementing individual methods in the class EmpresaDao
for example.
My mistake is being in the class project?
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 Empresadao
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();
}
}
}
}
Classe Dao
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();
}
}
}
}
You could add the complete codes, because your examples are in the informed codes. The method
this.Dao.ExisteRegistro();
is calling forPlanoDao
and notEmpresaDao
. AlreadyEmpresaDao
doesn’t have the méotodExisteRegistro
.– Gabriel Heming
I didn’t add the entire class to avoid polluting the code, but I added part of the class
PlanoDao
;– Macario1983