Created
August 7, 2018 18:45
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
/* | |
* Class called Emailer to send email alerts | |
*/ | |
public class Emailer { | |
public String generateJobAlert(String job) { | |
String alert = "You are alerted for " + job; | |
return alert; | |
} | |
} | |
/* | |
* Class called Phone to send phone alerts | |
*/ | |
public class Phone { | |
public String generateJobAlert(String job) { | |
String alert = "You are alerted for " + job; | |
return alert; | |
} | |
} | |
/* | |
* Class called JobTracker. | |
* This class initializes both the Phone & Email class | |
* This is a violation of the DIP principle | |
*/ | |
public class JobTracker { | |
private Phone phone; | |
private Emailer emailer; | |
public JobTracker() { | |
phone = new Phone(); | |
emailer = new Emailer(); | |
} | |
/* | |
* Based on the jobDescription, the alert is sent | |
* This logic should not be implemented here! | |
*/ | |
public void setCurrentConditions(String jobDescription) { | |
if (jobDescription == "urgent") { | |
String alert = phone.generateJobAlert(jobDescription); | |
System.out.print(alert); | |
} | |
if (jobDescription == "brief") { | |
String alert = emailer.generateJobAlert(jobDescription); | |
System.out.print(alert); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment