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
@Bean | |
public Store store() { | |
Store store = new Store(); | |
store.setItem(item1()); | |
return store; | |
} |
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 Store { | |
private Item item; | |
public Store() { | |
item = new ItemImpl1(); | |
} | |
} | |
public class Store { | |
private Item item; | |
public Store(Item item) { |
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 WeatherTracker { | |
public String currentConditions; | |
public void setCurrentConditions(String weatherDescription) { | |
this.currentConditions = weatherDescription; | |
} | |
public void notify(Notifier notifier) { | |
notifier.alertWeatherConditions(currentConditions); | |
} |
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 Notifier { | |
void alertWeatherConditions(String weatherConditions); | |
} | |
public class Email implements Notifier { | |
@Override | |
public void alertWeatherConditions(String weatherConditions) { | |
if (weatherConditions == "sunny"); | |
System.out.print("It is sunny"); | |
} |
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 WeatherTracker { | |
public String currentConditions; | |
private Phone phone; | |
private Emailer emailer; | |
public WeatherTracker() { | |
phone = new Phone(); | |
emailer = new Emailer(); | |
} |
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 CurrentAccount extends Account implements Deposable, Withdrawable { | |
@Override | |
protected void deposit(BigDecimal amount) { | |
// Deposit into CurrentAccount | |
} | |
@Override | |
protected void withdraw(BigDecimal amount) { | |
// Withdraw from CurrentAccount | |
} | |
} |
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 Depositable { | |
void deposit(BigDecimal amount); | |
} | |
public interface Withdrawable { | |
void withdraw(BigDecimal amount); | |
} | |
public abstract class Account { | |
// keep for private | |
} |
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 abstract class Account { | |
protected abstract void deposit(BigDecimal amount); | |
protected abstract void withdraw(BigDecimal amount); | |
} | |
/** | |
* Empty method | |
*/ | |
public class FixedTermDepositAccount extends Account { |
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 BasicPrinter implements Printer { | |
@Override | |
public boolean print() { | |
//Logic for printing | |
return true; | |
} | |
} | |
public class BasicScanner implements Scan { | |
@Override | |
public boolean scan() { |
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 Scan { | |
boolean scan(); | |
} | |
public interface Printer { | |
boolean print(); | |
} | |
public interface Fax { | |
boolean fax(); | |
} | |
public class MultifunctionalFaxPrinter implements Printer, Fax, Scan { |