From beead1848c77072d2c729f1e9e0835c3920e47ea Mon Sep 17 00:00:00 2001 From: Sufyan Date: Sun, 9 Mar 2025 01:31:06 +0530 Subject: [PATCH 1/4] SUF-19 Requirement to add new Email sending service --- Main.java | 16 ++++++++++++++-- api/EmailService.java | 10 ++++++++++ game/Player.java | 5 +++++ game/User.java | 12 ++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 api/EmailService.java create mode 100644 game/User.java diff --git a/Main.java b/Main.java index f0d48b7..5531df7 100644 --- a/Main.java +++ b/Main.java @@ -1,4 +1,5 @@ import api.AIEngine; +import api.EmailService; import api.GameEngine; import api.RuleEngine; import boards.History; @@ -10,6 +11,8 @@ import java.util.Scanner; +import static java.util.concurrent.TimeUnit.DAYS; + public class Main { public static void main(String[] args) { @@ -19,10 +22,14 @@ public static void main(String[] args) { RuleEngine ruleEngine = new RuleEngine(); Board board = gameEngine.start("TicTacToe"); Scanner scanner = new Scanner(System.in); + Player computer = new Player("O"); + Player opponent = new Player("X"); + if(opponent.getUser().activeAfter(1,DAYS)){ + EmailService emailService = new EmailService(); + emailService.sendEmail(opponent.getUser(), "We are glad that you are back"); + } while(!ruleEngine.getState(board).isOver()){ System.out.println("Make your Move"); - Player computer = new Player("O"); - Player opponent = new Player("X"); int row = scanner.nextInt(); int col = scanner.nextInt(); Move opponentMove = new Move(opponent,new Cell(row,col)); @@ -38,6 +45,11 @@ public static void main(String[] args) { History boardHistory = board1.getHistory(); boardHistory.printHistory(); } + // Problem with below approach is that it is not extensible, if link support, image support is needed then we had to change everywhere + if(ruleEngine.getState(board).getWinner().equals(opponent.symbol())){ + EmailService emailService = new EmailService(); + emailService.sendEmail(opponent.getUser(), "Congratulation , you have won the match"); + } System.out.println("Game winner is " + ruleEngine.getState(board).getWinner()); } diff --git a/api/EmailService.java b/api/EmailService.java new file mode 100644 index 0000000..569e3d2 --- /dev/null +++ b/api/EmailService.java @@ -0,0 +1,10 @@ +package api; + +import game.Player; +import game.User; + +public class EmailService { + public void sendEmail(User user, String message){ + return; + } +} diff --git a/game/Player.java b/game/Player.java index 101b3cc..b6599c8 100644 --- a/game/Player.java +++ b/game/Player.java @@ -2,8 +2,10 @@ public class Player { private final String playerSymbol; + private User user; public Player(String playerSymbol){ this.playerSymbol=playerSymbol; + this.user = new User(); } public String symbol(){ return playerSymbol; @@ -11,4 +13,7 @@ public String symbol(){ public Player flip(){ return new Player(playerSymbol.equals("X") ? "O":"X"); } + public User getUser() { + return user; + } } diff --git a/game/User.java b/game/User.java new file mode 100644 index 0000000..88717d3 --- /dev/null +++ b/game/User.java @@ -0,0 +1,12 @@ +package game; + +import java.util.concurrent.TimeUnit; + +public class User { + int id; + long lastActiveTime; + + public boolean activeAfter(int threshold, TimeUnit timeUnit){ + return System.currentTimeMillis()-lastActiveTime>timeUnit.toMillis(threshold); + } +} From 609a6e271f427d7e19d4055d08961a579bf5243a Mon Sep 17 00:00:00 2001 From: Sufyan Date: Mon, 10 Mar 2025 22:03:04 +0530 Subject: [PATCH 2/4] SUF-19 We have used the command pattern with inheritance on the Email and SMS layer but that does not seem to work : It is adding more complexities and anti patterns. --- Main.java | 18 ++++++++----- Service/EmailService.java | 13 ++++++++++ Service/SMSService.java | 14 +++++++++++ api/EmailService.java | 10 -------- commands/builder/SendBuilder.java | 24 ++++++++++++++++++ commands/builder/SendEmailCommandBuilder.java | 25 +++++++++++++++++++ commands/builder/SendSMSCommandBuilder.java | 21 ++++++++++++++++ commands/implementation/Send.java | 22 ++++++++++++++++ commands/implementation/SendEmailCommand.java | 13 ++++++++++ commands/implementation/SendSMSCommand.java | 12 +++++++++ 10 files changed, 156 insertions(+), 16 deletions(-) create mode 100644 Service/EmailService.java create mode 100644 Service/SMSService.java delete mode 100644 api/EmailService.java create mode 100644 commands/builder/SendBuilder.java create mode 100644 commands/builder/SendEmailCommandBuilder.java create mode 100644 commands/builder/SendSMSCommandBuilder.java create mode 100644 commands/implementation/Send.java create mode 100644 commands/implementation/SendEmailCommand.java create mode 100644 commands/implementation/SendSMSCommand.java diff --git a/Main.java b/Main.java index 5531df7..078ce87 100644 --- a/Main.java +++ b/Main.java @@ -1,9 +1,12 @@ -import api.AIEngine; -import api.EmailService; -import api.GameEngine; -import api.RuleEngine; +import Service.EmailService; +import Service.SMSService; +import api.*; import boards.History; import boards.TicTacToeBoard; +import commands.builder.SendEmailCommandBuilder; +import commands.builder.SendSMSCommandBuilder; +import commands.implementation.SendEmailCommand; +import commands.implementation.SendSMSCommand; import game.Board; import game.Cell; import game.Move; @@ -26,7 +29,7 @@ public static void main(String[] args) { Player opponent = new Player("X"); if(opponent.getUser().activeAfter(1,DAYS)){ EmailService emailService = new EmailService(); - emailService.sendEmail(opponent.getUser(), "We are glad that you are back"); + emailService.execute((SendEmailCommand) new SendEmailCommandBuilder().user(opponent.getUser()).message("Glad, you are back").build()); } while(!ruleEngine.getState(board).isOver()){ System.out.println("Make your Move"); @@ -48,7 +51,10 @@ public static void main(String[] args) { // Problem with below approach is that it is not extensible, if link support, image support is needed then we had to change everywhere if(ruleEngine.getState(board).getWinner().equals(opponent.symbol())){ EmailService emailService = new EmailService(); - emailService.sendEmail(opponent.getUser(), "Congratulation , you have won the match"); + emailService.execute((SendEmailCommand) new SendEmailCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); + + SMSService smsService = new SMSService(); + smsService.execute((SendSMSCommand) new SendSMSCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); } System.out.println("Game winner is " + ruleEngine.getState(board).getWinner()); } diff --git a/Service/EmailService.java b/Service/EmailService.java new file mode 100644 index 0000000..0ccc20e --- /dev/null +++ b/Service/EmailService.java @@ -0,0 +1,13 @@ +package Service; + +import commands.implementation.SendEmailCommand; +import game.User; + +public class EmailService { + private void sendEmail(User user, String message){ + System.out.println("sendEmail has been envoked"); + } + public void execute(SendEmailCommand command){ + sendEmail(command.getReciever(),command.getMessage()); + } +} diff --git a/Service/SMSService.java b/Service/SMSService.java new file mode 100644 index 0000000..b27e884 --- /dev/null +++ b/Service/SMSService.java @@ -0,0 +1,14 @@ +package Service; + +import commands.implementation.SendEmailCommand; +import commands.implementation.SendSMSCommand; +import game.User; + +public class SMSService { + private void sendSMS(User user, String message){ + System.out.println("sendEmail has been envoked"); + } + public void execute(SendSMSCommand command){ + sendSMS(command.getReciever(),command.getMessage()); + } +} \ No newline at end of file diff --git a/api/EmailService.java b/api/EmailService.java deleted file mode 100644 index 569e3d2..0000000 --- a/api/EmailService.java +++ /dev/null @@ -1,10 +0,0 @@ -package api; - -import game.Player; -import game.User; - -public class EmailService { - public void sendEmail(User user, String message){ - return; - } -} diff --git a/commands/builder/SendBuilder.java b/commands/builder/SendBuilder.java new file mode 100644 index 0000000..5222387 --- /dev/null +++ b/commands/builder/SendBuilder.java @@ -0,0 +1,24 @@ +package commands.builder; + +import commands.implementation.Send; +import commands.implementation.SendEmailCommand; +import game.User; + +public class SendBuilder { + + User user; + String message; + + public SendBuilder user(User user){ + this.user = user; + return this; + } + public SendBuilder message(String message){ + this.message = message; + return this; + } + + public Send build(){ + return new Send(user,message); + } +} diff --git a/commands/builder/SendEmailCommandBuilder.java b/commands/builder/SendEmailCommandBuilder.java new file mode 100644 index 0000000..db79404 --- /dev/null +++ b/commands/builder/SendEmailCommandBuilder.java @@ -0,0 +1,25 @@ +package commands.builder; + +import commands.implementation.Send; +import commands.implementation.SendEmailCommand; +import game.User; + +public class SendEmailCommandBuilder extends SendBuilder{ + String link; + String templateId; + String tempalate; + + + public SendEmailCommandBuilder link(String link){ + this.link = link; + return this; + } + public SendEmailCommandBuilder templateId(String templateId){ + this.templateId = templateId; + return this; + } + public SendEmailCommandBuilder template(String template){ + this.tempalate = template; + return this; + } +} diff --git a/commands/builder/SendSMSCommandBuilder.java b/commands/builder/SendSMSCommandBuilder.java new file mode 100644 index 0000000..e52f116 --- /dev/null +++ b/commands/builder/SendSMSCommandBuilder.java @@ -0,0 +1,21 @@ +package commands.builder; + +import commands.implementation.SendSMSCommand; + + +public class SendSMSCommandBuilder extends SendBuilder{ + String templateId; + String template; + + public SendSMSCommandBuilder templateId(String templateId){ + this.templateId = templateId; + return this; + } + public SendSMSCommandBuilder template(String template){ + this.template = template; + return this; + } + public SendSMSCommand build(){ + return new SendSMSCommand(user,message); + } +} diff --git a/commands/implementation/Send.java b/commands/implementation/Send.java new file mode 100644 index 0000000..af4292b --- /dev/null +++ b/commands/implementation/Send.java @@ -0,0 +1,22 @@ +package commands.implementation; + +import game.User; + +public class Send { + + User reciever; + String message; + + public User getReciever() { + return reciever; + } + + public String getMessage() { + return message; + } + + public Send(User reciever, String message){ + this.reciever = reciever; + this.message = message; + } +} diff --git a/commands/implementation/SendEmailCommand.java b/commands/implementation/SendEmailCommand.java new file mode 100644 index 0000000..8c8ff8f --- /dev/null +++ b/commands/implementation/SendEmailCommand.java @@ -0,0 +1,13 @@ +package commands.implementation; + +import game.User; + +public class SendEmailCommand extends Send{ + String link; + String templateId; + String template; + + public SendEmailCommand(User user,String message){ + super(user,message); + } +} diff --git a/commands/implementation/SendSMSCommand.java b/commands/implementation/SendSMSCommand.java new file mode 100644 index 0000000..4a8fd29 --- /dev/null +++ b/commands/implementation/SendSMSCommand.java @@ -0,0 +1,12 @@ +package commands.implementation; + +import game.User; + +public class SendSMSCommand extends Send{ + String templateId; + String template; + + public SendSMSCommand(User user,String message){ + super(user,message); + } +} From 1c496c4206a4319b1000c7d8e6fbf074a437d3ae Mon Sep 17 00:00:00 2001 From: Sufyan Date: Wed, 12 Mar 2025 23:07:15 +0530 Subject: [PATCH 3/4] SUF-19 Instead of using inheritance , we have used composition - It do respect the SOLID principle but it is not extensible. Take a when we want to add whatsapp outreach for same event --- Main.java | 12 +++--- Service/EmailService.java | 6 +-- Service/SMSService.java | 7 ++-- commands/builder/EmailCommandBuilder.java | 37 +++++++++++++++++++ commands/builder/NotificationBuilder.java | 22 +++++++++++ commands/builder/SMSCommandBuilder.java | 32 ++++++++++++++++ commands/builder/SendBuilder.java | 24 ------------ commands/builder/SendEmailCommandBuilder.java | 25 ------------- commands/builder/SendSMSCommandBuilder.java | 21 ----------- commands/implementation/EmailCommand.java | 18 +++++++++ .../{Send.java => NotificationDetails.java} | 4 +- commands/implementation/SMSCommand.java | 17 +++++++++ commands/implementation/SendEmailCommand.java | 13 ------- commands/implementation/SendSMSCommand.java | 12 ------ 14 files changed, 139 insertions(+), 111 deletions(-) create mode 100644 commands/builder/EmailCommandBuilder.java create mode 100644 commands/builder/NotificationBuilder.java create mode 100644 commands/builder/SMSCommandBuilder.java delete mode 100644 commands/builder/SendBuilder.java delete mode 100644 commands/builder/SendEmailCommandBuilder.java delete mode 100644 commands/builder/SendSMSCommandBuilder.java create mode 100644 commands/implementation/EmailCommand.java rename commands/implementation/{Send.java => NotificationDetails.java} (75%) create mode 100644 commands/implementation/SMSCommand.java delete mode 100644 commands/implementation/SendEmailCommand.java delete mode 100644 commands/implementation/SendSMSCommand.java diff --git a/Main.java b/Main.java index 078ce87..e29cce0 100644 --- a/Main.java +++ b/Main.java @@ -3,10 +3,8 @@ import api.*; import boards.History; import boards.TicTacToeBoard; -import commands.builder.SendEmailCommandBuilder; -import commands.builder.SendSMSCommandBuilder; -import commands.implementation.SendEmailCommand; -import commands.implementation.SendSMSCommand; +import commands.builder.EmailCommandBuilder; +import commands.builder.SMSCommandBuilder; import game.Board; import game.Cell; import game.Move; @@ -29,7 +27,7 @@ public static void main(String[] args) { Player opponent = new Player("X"); if(opponent.getUser().activeAfter(1,DAYS)){ EmailService emailService = new EmailService(); - emailService.execute((SendEmailCommand) new SendEmailCommandBuilder().user(opponent.getUser()).message("Glad, you are back").build()); + emailService.execute(new EmailCommandBuilder().user(opponent.getUser()).message("Glad, you are back").build()); } while(!ruleEngine.getState(board).isOver()){ System.out.println("Make your Move"); @@ -51,10 +49,10 @@ public static void main(String[] args) { // Problem with below approach is that it is not extensible, if link support, image support is needed then we had to change everywhere if(ruleEngine.getState(board).getWinner().equals(opponent.symbol())){ EmailService emailService = new EmailService(); - emailService.execute((SendEmailCommand) new SendEmailCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); + emailService.execute(new EmailCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); SMSService smsService = new SMSService(); - smsService.execute((SendSMSCommand) new SendSMSCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); + smsService.execute(new SMSCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); } System.out.println("Game winner is " + ruleEngine.getState(board).getWinner()); } diff --git a/Service/EmailService.java b/Service/EmailService.java index 0ccc20e..28541dd 100644 --- a/Service/EmailService.java +++ b/Service/EmailService.java @@ -1,13 +1,13 @@ package Service; -import commands.implementation.SendEmailCommand; +import commands.implementation.EmailCommand; import game.User; public class EmailService { private void sendEmail(User user, String message){ System.out.println("sendEmail has been envoked"); } - public void execute(SendEmailCommand command){ - sendEmail(command.getReciever(),command.getMessage()); + public void execute(EmailCommand command){ + sendEmail(command.getNotificationDetails().getReciever(),command.getNotificationDetails().getMessage()); } } diff --git a/Service/SMSService.java b/Service/SMSService.java index b27e884..68551f0 100644 --- a/Service/SMSService.java +++ b/Service/SMSService.java @@ -1,14 +1,13 @@ package Service; -import commands.implementation.SendEmailCommand; -import commands.implementation.SendSMSCommand; +import commands.implementation.SMSCommand; import game.User; public class SMSService { private void sendSMS(User user, String message){ System.out.println("sendEmail has been envoked"); } - public void execute(SendSMSCommand command){ - sendSMS(command.getReciever(),command.getMessage()); + public void execute(SMSCommand command){ + sendSMS(command.getNotificationDetails().getReciever(),command.getNotificationDetails().getMessage()); } } \ No newline at end of file diff --git a/commands/builder/EmailCommandBuilder.java b/commands/builder/EmailCommandBuilder.java new file mode 100644 index 0000000..eaecf85 --- /dev/null +++ b/commands/builder/EmailCommandBuilder.java @@ -0,0 +1,37 @@ +package commands.builder; + + +import commands.implementation.EmailCommand; +import game.User; + +public class EmailCommandBuilder { + NotificationBuilder notificationBuilder; + String link; + String templateId; + String tempalate; + + + public EmailCommandBuilder link(String link){ + this.link = link; + return this; + } + public EmailCommandBuilder templateId(String templateId){ + this.templateId = templateId; + return this; + } + public EmailCommandBuilder user(User user){ + this.notificationBuilder.user(user); + return this; + } + public EmailCommandBuilder message(String message){ + this.notificationBuilder.message(message); + return this; + } + public EmailCommandBuilder template(String template){ + this.tempalate = template; + return this; + } + public EmailCommand build(){ + return new EmailCommand(notificationBuilder.build()); + } +} diff --git a/commands/builder/NotificationBuilder.java b/commands/builder/NotificationBuilder.java new file mode 100644 index 0000000..9c24878 --- /dev/null +++ b/commands/builder/NotificationBuilder.java @@ -0,0 +1,22 @@ +package commands.builder; + +import commands.implementation.NotificationDetails; +import game.User; + +public class NotificationBuilder { + + User user; + String message; + + public NotificationBuilder user(User user){ + this.user = user; + return this; + } + public NotificationBuilder message(String message){ + this.message = message; + return this; + } + public NotificationDetails build(){ + return new NotificationDetails(user,message); + } +} diff --git a/commands/builder/SMSCommandBuilder.java b/commands/builder/SMSCommandBuilder.java new file mode 100644 index 0000000..c32b76b --- /dev/null +++ b/commands/builder/SMSCommandBuilder.java @@ -0,0 +1,32 @@ +package commands.builder; + +import commands.implementation.SMSCommand; +import game.User; + + +public class SMSCommandBuilder { + NotificationBuilder notificationBuilder; + String templateId; + String template; + + public SMSCommandBuilder templateId(String templateId){ + this.templateId = templateId; + return this; + } + public SMSCommandBuilder template(String template){ + this.template = template; + return this; + } + public SMSCommandBuilder user(User user){ + this.notificationBuilder.user(user); + return this; + } + public SMSCommandBuilder message(String message){ + this.notificationBuilder.message(message); + return this; + } + public SMSCommand build(){ + return new SMSCommand(notificationBuilder.build()); + } + +} diff --git a/commands/builder/SendBuilder.java b/commands/builder/SendBuilder.java deleted file mode 100644 index 5222387..0000000 --- a/commands/builder/SendBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -package commands.builder; - -import commands.implementation.Send; -import commands.implementation.SendEmailCommand; -import game.User; - -public class SendBuilder { - - User user; - String message; - - public SendBuilder user(User user){ - this.user = user; - return this; - } - public SendBuilder message(String message){ - this.message = message; - return this; - } - - public Send build(){ - return new Send(user,message); - } -} diff --git a/commands/builder/SendEmailCommandBuilder.java b/commands/builder/SendEmailCommandBuilder.java deleted file mode 100644 index db79404..0000000 --- a/commands/builder/SendEmailCommandBuilder.java +++ /dev/null @@ -1,25 +0,0 @@ -package commands.builder; - -import commands.implementation.Send; -import commands.implementation.SendEmailCommand; -import game.User; - -public class SendEmailCommandBuilder extends SendBuilder{ - String link; - String templateId; - String tempalate; - - - public SendEmailCommandBuilder link(String link){ - this.link = link; - return this; - } - public SendEmailCommandBuilder templateId(String templateId){ - this.templateId = templateId; - return this; - } - public SendEmailCommandBuilder template(String template){ - this.tempalate = template; - return this; - } -} diff --git a/commands/builder/SendSMSCommandBuilder.java b/commands/builder/SendSMSCommandBuilder.java deleted file mode 100644 index e52f116..0000000 --- a/commands/builder/SendSMSCommandBuilder.java +++ /dev/null @@ -1,21 +0,0 @@ -package commands.builder; - -import commands.implementation.SendSMSCommand; - - -public class SendSMSCommandBuilder extends SendBuilder{ - String templateId; - String template; - - public SendSMSCommandBuilder templateId(String templateId){ - this.templateId = templateId; - return this; - } - public SendSMSCommandBuilder template(String template){ - this.template = template; - return this; - } - public SendSMSCommand build(){ - return new SendSMSCommand(user,message); - } -} diff --git a/commands/implementation/EmailCommand.java b/commands/implementation/EmailCommand.java new file mode 100644 index 0000000..891bff7 --- /dev/null +++ b/commands/implementation/EmailCommand.java @@ -0,0 +1,18 @@ +package commands.implementation; + +import game.User; + +public class EmailCommand { + NotificationDetails notificationDetails; + String link; + String templateId; + String template; + + public EmailCommand(NotificationDetails notificationDetails){ + notificationDetails = new NotificationDetails(notificationDetails.getReciever(),notificationDetails.getMessage()); + } + + public NotificationDetails getNotificationDetails() { + return notificationDetails; + } +} diff --git a/commands/implementation/Send.java b/commands/implementation/NotificationDetails.java similarity index 75% rename from commands/implementation/Send.java rename to commands/implementation/NotificationDetails.java index af4292b..723d6ae 100644 --- a/commands/implementation/Send.java +++ b/commands/implementation/NotificationDetails.java @@ -2,7 +2,7 @@ import game.User; -public class Send { +public class NotificationDetails { User reciever; String message; @@ -15,7 +15,7 @@ public String getMessage() { return message; } - public Send(User reciever, String message){ + public NotificationDetails(User reciever, String message){ this.reciever = reciever; this.message = message; } diff --git a/commands/implementation/SMSCommand.java b/commands/implementation/SMSCommand.java new file mode 100644 index 0000000..7bdc046 --- /dev/null +++ b/commands/implementation/SMSCommand.java @@ -0,0 +1,17 @@ +package commands.implementation; + +import game.User; + +public class SMSCommand { + NotificationDetails notificationDetails; + String templateId; + String template; + + public SMSCommand(NotificationDetails notificationDetails){ + notificationDetails = new NotificationDetails(notificationDetails.getReciever(),notificationDetails.getMessage()); + } + + public NotificationDetails getNotificationDetails() { + return notificationDetails; + } +} diff --git a/commands/implementation/SendEmailCommand.java b/commands/implementation/SendEmailCommand.java deleted file mode 100644 index 8c8ff8f..0000000 --- a/commands/implementation/SendEmailCommand.java +++ /dev/null @@ -1,13 +0,0 @@ -package commands.implementation; - -import game.User; - -public class SendEmailCommand extends Send{ - String link; - String templateId; - String template; - - public SendEmailCommand(User user,String message){ - super(user,message); - } -} diff --git a/commands/implementation/SendSMSCommand.java b/commands/implementation/SendSMSCommand.java deleted file mode 100644 index 4a8fd29..0000000 --- a/commands/implementation/SendSMSCommand.java +++ /dev/null @@ -1,12 +0,0 @@ -package commands.implementation; - -import game.User; - -public class SendSMSCommand extends Send{ - String templateId; - String template; - - public SendSMSCommand(User user,String message){ - super(user,message); - } -} From 4b3e1ab71d299e0cbb3217523fc61692d4f01a97 Mon Sep 17 00:00:00 2001 From: Sufyan Date: Sat, 15 Mar 2025 20:39:45 +0530 Subject: [PATCH 4/4] SUF-19 We are using pub sub model to decouple behaviours --- Events/Event.java | 18 ++++++++++++++++++ Events/EventBus.java | 21 +++++++++++++++++++++ Events/Subscriber.java | 9 +++++++++ Events/WinEvent.java | 5 +++++ Main.java | 2 +- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Events/Event.java create mode 100644 Events/EventBus.java create mode 100644 Events/Subscriber.java create mode 100644 Events/WinEvent.java diff --git a/Events/Event.java b/Events/Event.java new file mode 100644 index 0000000..e744bda --- /dev/null +++ b/Events/Event.java @@ -0,0 +1,18 @@ +package Events; + + +import game.User; + +public abstract class Event { + + private User user; + private String message; + + public String getMessage() { + return message; + } + + public User getUser() { + return user; + } +} diff --git a/Events/EventBus.java b/Events/EventBus.java new file mode 100644 index 0000000..6f348d9 --- /dev/null +++ b/Events/EventBus.java @@ -0,0 +1,21 @@ +package Events; + +import java.util.List; + +public class EventBus { + List events; + List subscriber; + + public List getEvents() { + return events; + } + + public void addEvents(Event event) { + this.events.add(event); + } + + public void setSubscriber(Subscriber subscriber) { + this.subscriber.add(subscriber); + } + +} diff --git a/Events/Subscriber.java b/Events/Subscriber.java new file mode 100644 index 0000000..64ad308 --- /dev/null +++ b/Events/Subscriber.java @@ -0,0 +1,9 @@ +package Events; + +import java.util.function.Function; + +public class Subscriber { + + Subscriber(Function function){ + } +} diff --git a/Events/WinEvent.java b/Events/WinEvent.java new file mode 100644 index 0000000..5f0abb6 --- /dev/null +++ b/Events/WinEvent.java @@ -0,0 +1,5 @@ +package Events; + +public class WinEvent extends Event{ + +} diff --git a/Main.java b/Main.java index e29cce0..332bdc4 100644 --- a/Main.java +++ b/Main.java @@ -49,7 +49,7 @@ public static void main(String[] args) { // Problem with below approach is that it is not extensible, if link support, image support is needed then we had to change everywhere if(ruleEngine.getState(board).getWinner().equals(opponent.symbol())){ EmailService emailService = new EmailService(); - emailService.execute(new EmailCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build()); + emailService.execute(new EmailCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").link("https://suii.com").build()); SMSService smsService = new SMSService(); smsService.execute(new SMSCommandBuilder().user(opponent.getUser()).message("Congratulations, you won the match").build());