Вопрос пользователя:
Ответ нейросети:
import java.util.List;
interface Notification {
String getMessage();
String getAdditionalFields();
}
class SmsNotification implements Notification {
private String message;
private String additionalFields;
public SmsNotification(String message, String additionalFields) {
this.message = message;
this.additionalFields = additionalFields;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getAdditionalFields() {
return additionalFields;
}
}
class EmailNotification implements Notification {
private String message;
private String additionalFields;
public EmailNotification(String message, String additionalFields) {
this.message = message;
this.additionalFields = additionalFields;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getAdditionalFields() {
return additionalFields;
}
}
class PushNotification implements Notification {
private String message;
private String additionalFields;
public PushNotification(String message, String additionalFields) {
this.message = message;
this.additionalFields = additionalFields;
}
@Override
public String getMessage() {
return message;
}
@Override
public String getAdditionalFields() {
return additionalFields;
}
}
interface NotificationSender<T extends Notification> {
void send(T notification);
void send(List<T> notifications);
}
class SmsNotificationSender implements NotificationSender<SmsNotification> {
@Override
public void send(SmsNotification notification) {
System.out.println("Sending SMS notification:");
System.out.println("Message: " + notification.getMessage());
System.out.println("Additional Fields: " + notification.getAdditionalFields());
}
@Override
public void send(List<SmsNotification> notifications) {
for (SmsNotification notification : notifications) {
send(notification);
}
}
}
class EmailNotificationSender implements NotificationSender<EmailNotification> {
@Override
public void send(EmailNotification notification) {
System.out.println("Sending Email notification:");
System.out.println("Message: " + notification.getMessage());
System.out.println("Additional Fields: " + notification.getAdditionalFields());
}
@Override
public void send(List<EmailNotification> notifications) {
for (EmailNotification notification : notifications) {
send(notification);
}
}
}
class PushNotificationSender implements NotificationSender<PushNotification> {
@Override
public void send(PushNotification notification) {
System.out.println("Sending Push notification:");
System.out.println("Message: " + notification.getMessage());
System.out.println("Additional Fields: " + notification.getAdditionalFields());
}
@Override
public void send(List<PushNotification> notifications) {
for (PushNotification notification : notifications) {
send(notification);
}
}
}
public class Main {
public static void main(String[] args) {
SmsNotificationSender smsSender = new SmsNotificationSender();
EmailNotificationSender emailSender = new EmailNotificationSender();
PushNotificationSender pushSender = new PushNotificationSender();
SmsNotification smsNotification = new SmsNotification("Hello from SMS", "Sender: John");
EmailNotification emailNotification = new EmailNotification("Hello from Email", "Sender: Jane");
PushNotification pushNotification = new PushNotification("Hello from Push", "Sender: Alice");
smsSender.send(smsNotification);
emailSender.send(emailNotification);
pushSender.send(pushNotification);
List<SmsNotification> smsNotifications = List.of(smsNotification, new SmsNotification("Second SMS", "Sender: Bob"));
List<EmailNotification> emailNotifications = List.of(emailNotification, new EmailNotification("Second Email", "Sender: Mary"));
List<PushNotification> pushNotifications = List.of(pushNotification, new PushNotification("Second Push", "Sender: Eve"));
smsSender.send(smsNotifications);
emailSender.send(emailNotifications);
pushSender.send(pushNotifications);
}
}
Обратите внимание: ответы, предоставляемые искусственным интеллектом, могут не всегда быть точными. Не рассчитывайте на них в критически важных областях, таких как медицина, юриспруденция, финансы или в вопросах, связанных с безопасностью. Для важных решений всегда обращайтесь к квалифицированным специалистам. Администрация сайта не несет ответственности за контент, сгенерированный автоматически.