Using interfaces for domain classes

3

Is it a good practice to make use of interfaces for domain class? Do I have an advantage doing this? If so, which one?

Example:

public interface IAuditoria
{
    long AuditoriaID { get; set; }
    string Descricao { get; set; }
    string SistemaOperacional { get; set; }
    string ResolucaoTela { get; set; }
    string ModeloDevice { get; set; }
    string Navegador { get; set; }
    string IPInternet { get; set; }
    string Geolocalizacao { get; set; }
    DateTime DataAuditoria { get; set; }
}

public class Auditoria : Entities.Bases.EntityBase, Entities.Interfaces.IAuditoria
{
    public Auditoria()
    {

    }

    #region Properties

    public long AuditoriaID { get; set; }
    public string Descricao { get; set; }
    public string SistemaOperacional { get; set; }
    public string ResolucaoTela { get; set; }
    public string ModeloDevice { get; set; }
    public string Navegador { get; set; }
    public string IPInternet { get; set; }
    public string Geolocalizacao { get; set; }
    public DateTime DataAuditoria { get; set; }
}
    
asked by anonymous 25.07.2018 / 19:14

2 answers

6

Creating by creating without a reason has no advantage. In everything you do, everything, even putting a blank in the code needs to find a motivation.

That's why I always tell people to let go of this good practice thing. In practice they cater to people following cake recipes without thinking about what they are doing.

Can you find a reason?

I can say one: have an abstraction to be able to accept a generic type and the concrete be different in each situation. This is called Programming interface-oriented, not for implementation, why? .

Do you need this abstraction?

If you do not have this generality, I do not see why.

There is a case that people say to do even if their domain does not need it, that is the test. Without it, it's a bit more complicated to test other things without being able to change the implementation. It is questionable whether it is worth complicating the design to just facilitate the test.

Still, do you need to change the implementation to be able to do a better test?

I still do not think I need to.

It's not what you do that matters, it's what you do.

    
25.07.2018 / 19:59
1

The advantage of the interface is to use its behavior, regardless of the type of the object.

Example.

interface IAnimal{
        void Respira();
}
class Cachorro : IAnimal
{
 void Respira()
 {
 //Respira de um jeito
 }
}

class Gato : IAnimal
{ 
  void Respira()
  {
     //Respira de outro um jeito
  }
}

If you have a list of the type of the interface and scroll through it, even if the objects placed on it are different, you have the advantage of calling them. Already in a domain class, which serves only to maintain the "design" of the data ... you do not have a clear advantage of it, you may have, depending on your interpretation of the problem.

It may be interesting to maintain an organization and possibly help in something further, but on a whim I can not find a justification. It's worth a debate.

    
26.07.2018 / 19:47