jeudi 13 juin 2019

Generic Email Sender in Java

I am new to object-oriented programming. I want to create Email Body based on the EnumType I receive from the request from the UI.

For example, if I receive Enum value A, I need to build an email body with some attributes which I receive from a database and other services. I need different behavior if the Enum value is different.

I tried to Create

public interface EmailService {
  String getBody();
  String getStatus();
}

public class AEmailService implements EmailService {
  Service X;
  DAOService Y;

   .... Some operations.

}

public class BEmailService implements EmailService {
  Service X;
  DAOService Y;
   .... Some operations.

}


Now, how can I use the EmailService interface and replace it with the objects of AEmailService or BEmailService on runtime based on the enum value in the request.

Is it better to do to perform this?

Aucun commentaire:

Enregistrer un commentaire