Last active
March 7, 2018 22:23
-
-
Save michal-lipski/892392ec1a05f84e20aae22f7fe2947c to your computer and use it in GitHub Desktop.
inversion_of_controll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.email; | |
public interface EmailSender { | |
void send(String recipient, String message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.notifications; | |
import com.app.email.RealEmailSender; | |
public class NotificationsPolicy { | |
private RealEmailSender emailSender = new RealEmailSender(); | |
public void fireNotification(){ | |
emailSender.send("john@gmail.com", "message"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.notifications; | |
import com.app.email.EmailSender; | |
import com.app.email.RealEmailSender; | |
public class NotificationsPolicy { | |
private EmailSender notificationSender; | |
public NotificationsPolicy(EmailSender notificationSender) { | |
this.notificationSender = notificationSender; | |
} | |
public void fireNotification() { | |
notificationSender.send("john@gmail.com","message"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.notifications; | |
import com.app.email.EmailSender; | |
import com.app.email.RealEmailSender; | |
public class NotificationsPolicy { | |
private EmailSender notificationSender = new RealEmailSender(); | |
public void fireNotification() { | |
notificationSender.send("john@gmail.com","message"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.adapter; | |
import com.app.notifications.NotificationGateway; | |
import com.app.sms.SmsSenderApi; | |
public class SmsAdapter implements NotificationGateway { | |
private SmsSenderApi smsSenderApi; | |
public SmsAdapter(SmsSenderApi smsSenderApi) { | |
this.smsSenderApi = smsSenderApi; | |
} | |
@Override | |
public void send(String recipient, String message) { | |
smsSenderApi.sendSms(message, recipient); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment