Skip to content

Instantly share code, notes, and snippets.

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