Skip to content

Instantly share code, notes, and snippets.

Avatar

CosmoX hackjutsu

View GitHub Profile
@hackjutsu
hackjutsu / MP3PlayerContext.java
Created May 23, 2019
[medium snippets] #medium #designPattern #StatePattern
View MP3PlayerContext.java
public class MP3PlayerContext {
private State state;
public MP3PlayerContext() {
this.state = new StandbyState();
}
public void press() {
state.pressPlay(this);
}
@hackjutsu
hackjutsu / StreetMap.java
Created May 20, 2019
[medium snippets] #medium #designPattern #BuilderPattern
View StreetMap.java
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 {
@hackjutsu
hackjutsu / ProxyPatternDemo.java
Created May 20, 2019
[medium snippets] #medium #designPattern #ProxyPattern
View ProxyPatternDemo.java
public class ProxyPatternDemo {
public static void main(String[] args) {
Image image = new ProxyImage("test_10mb.jpg");
image.display();
System.out.println("");
image.display();
}
}
@hackjutsu
hackjutsu / ProxyImage.java
Created May 20, 2019
[medium snippets] #medium #designPattern #ProxyPattern
View ProxyImage.java
public class ProxyImage implements Image{
private RealImage realImage;
private String fileName;
public ProxyImage(String fileName){
this.fileName = fileName;
}
@Override
public void display() {
@hackjutsu
hackjutsu / RealImage.java
Created May 20, 2019
[medium snippets] #medium #designPattern #ProxyPattern
View RealImage.java
public class RealImage implements Image {
private String fileName;
public RealImage(String fileName){
this.fileName = fileName;
loadFromDisk(fileName);
}
@Override
public void display() {
@hackjutsu
hackjutsu / Image.java
Created May 20, 2019
[medium snippets] #medium #designPattern #ProxyPattern
View Image.java
public interface Image {
void display();
}
@hackjutsu
hackjutsu / ClientMain.java
Created May 20, 2019
[medium snippets] #medium #designPattern #FacadePattern
View ClientMain.java
public class ClientMain {
public static void main(String[] args) {
ComputerFacade computer = new ComputerFacade();
computer.start();
}
}
@hackjutsu
hackjutsu / ComputerFacade.java
Created May 20, 2019
[medium snippets] #medium #designPattern #FacadePattern
View ComputerFacade.java
public class ComputerFacade {
static private final long BOOT_ADDRESS = 0;
static private final long BOOT_SECTOR = 0;
static private final int SECTOR_SIZE = 0;
private CPU processor;
private Memory ram;
private HardDrive hd;
public ComputerFacade() {
@hackjutsu
hackjutsu / Memory.java
Created May 20, 2019
[medium snippets] #medium #designPattern #FacadePattern
View Memory.java
public class Memory {
public void load(long position, byte[] data) {
System.out.println("Memory: loading... " );
}
}
@hackjutsu
hackjutsu / HardDrive.java
Created May 20, 2019
[medium snippets] #medium #designPattern #FacadePattern
View HardDrive.java
public class HardDrive {
public byte[] read(long lba, int size) {
System.out.println("HardDrive: reading...");
return null;
}
}