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
public class ClientDemo { | |
public static void main(String[] args) { | |
MP3PlayerContext mp3Player = new MP3PlayerContext(); | |
mp3Player.press(); | |
mp3Player.getState(); | |
mp3Player.press(); | |
mp3Player.getState(); | |
} | |
} |
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
public class PlayingState implements State { | |
public void pressPlay(MP3PlayerContext context) { | |
context.setState(new StandbyState()); | |
} | |
@Override | |
public String getState() { | |
return "Playing..."; | |
} | |
} |
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
public interface State { | |
void pressPlay(MP3PlayerContext context); | |
String getState(); | |
} |
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
public class MP3PlayerContext { | |
private State state; | |
public MP3PlayerContext() { | |
this.state = new StandbyState(); | |
} | |
public void press() { | |
state.pressPlay(this); | |
} |
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
public class StreetMap { | |
private final Point origin; | |
private final Point destination; | |
private final Color waterColor; | |
private final Color landColor; | |
private final Color highTrafficColor; | |
private final Color mediumTrafficColor; | |
private final Color lowTrafficColor; | |
public static class Builder { |
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
public class ProxyPatternDemo { | |
public static void main(String[] args) { | |
Image image = new ProxyImage("test_10mb.jpg"); | |
image.display(); | |
System.out.println(""); | |
image.display(); | |
} | |
} |
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
public class ProxyImage implements Image{ | |
private RealImage realImage; | |
private String fileName; | |
public ProxyImage(String fileName){ | |
this.fileName = fileName; | |
} | |
@Override | |
public void display() { |
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
public class RealImage implements Image { | |
private String fileName; | |
public RealImage(String fileName){ | |
this.fileName = fileName; | |
loadFromDisk(fileName); | |
} | |
@Override | |
public void display() { |
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
public interface Image { | |
void display(); | |
} |
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
public class ClientMain { | |
public static void main(String[] args) { | |
ComputerFacade computer = new ComputerFacade(); | |
computer.start(); | |
} | |
} |