Created
August 7, 2018 18:45
-
-
Save anitaa1990/c39af79ddbc69a2799e2ff7cc2ee20f2 to your computer and use it in GitHub Desktop.
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
/* | |
* 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