Last active
August 29, 2015 14:08
-
-
Save up1/baf1c912123b569fd1c0 to your computer and use it in GitHub Desktop.
Demo :: DI
This file contains hidden or 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
| public class Email { | |
| public void send() { | |
| } | |
| } |
This file contains hidden or 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
| public class Email implements MessageService { | |
| public void send() { | |
| } | |
| } |
This file contains hidden or 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
| public interface MessageService { | |
| public void send(); | |
| } |
This file contains hidden or 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
| public class Notification { | |
| Email email; | |
| public Notification() { | |
| email = new Email(); | |
| } | |
| public void notifyPromotion() { | |
| email.send(); | |
| } | |
| } |
This file contains hidden or 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
| public class Notification { | |
| MessageService messageService; | |
| public Notification() { | |
| messageService = new Email(); | |
| } | |
| public void notifyPromotion() { | |
| messageService.send(); | |
| } | |
| } |
This file contains hidden or 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
| public class Notification { | |
| private MessageService messageService; | |
| public Notification(MessageService messageService) { | |
| this.messageService = messageService; | |
| } | |
| public void notifyPromotion() { | |
| messageService.send(); | |
| } | |
| } |
This file contains hidden or 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
| public class Notification { | |
| private MessageService messageService; | |
| public void setMessageService(MessageService messageService) { | |
| this.messageService = messageService; | |
| } | |
| public void notifyPromotion() { | |
| if (this.messageService != null) { | |
| messageService.send(); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| public class Notification { | |
| public void notifyPromotion(MessageService messageService) { | |
| messageService.send(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment