lundi 12 novembre 2018

Is it a bad practice to use service interface object in business code?

When talking about the communication between services, is it a bad practice to use interface object in business code? To clarify, interface here doesn't only refer to the special Interface structure in language, but refers to more general thing that are accessible to clients. Business code refers to the logic in service.

For example, the response of an API of service GetQualityOfACar is Quality, which contains a instance called Level:

@Data
public class Quality {
  private Level level;
  ...
}

Level is also a class in service GetQualityOfACar:

public class Level {
  public static final String HIGH = "High";
  public static final String MIDIUM = "Medium";
  public static final String LOW = "Low";
  public static final String UNKNOWN = "Unknown";
}

I heard people saying that using values in Level in business logic, like using Level.HIGH in business logic is a bad practice but I don't understand why. Can someone clarify it, or confirm if this is a bad practice or it doesn't matter?

Aucun commentaire:

Enregistrer un commentaire