Skip to content

Commit

Permalink
[Proxy] Added images examples and atm machine example
Browse files Browse the repository at this point in the history
  • Loading branch information
luisburgos committed Sep 21, 2015
1 parent bacd531 commit 365f40e
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/proxy/examples/atm/ATMClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package proxy.examples.atm;

/**
* Created by luisburgos on 21/09/15.
*/
public class ATMClient {

public static void main(String[] args) {

GetATMData realAtmMachine = new ATMMachine(1000);
GetATMData atmProxy = new ATMProxy(realAtmMachine);

System.out.println("ATM Machine, cash available: " + atmProxy.getCashInMachine());


}
}
17 changes: 17 additions & 0 deletions src/proxy/examples/atm/ATMMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package proxy.examples.atm;

/**
* Created by luisburgos on 21/09/15.
*/
public class ATMMachine implements GetATMData {

private int cashInMachine;

public ATMMachine(int cashInMachine){
this.cashInMachine = cashInMachine;
}
@Override
public int getCashInMachine() {
return cashInMachine;
}
}
18 changes: 18 additions & 0 deletions src/proxy/examples/atm/ATMProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package proxy.examples.atm;

/**
* Created by luisburgos on 21/09/15.
*/
public class ATMProxy implements GetATMData {

private GetATMData atmMachine;

public ATMProxy(GetATMData atmMachine){
this.atmMachine = atmMachine;
}

@Override
public int getCashInMachine() {
return atmMachine.getCashInMachine();
}
}
8 changes: 8 additions & 0 deletions src/proxy/examples/atm/GetATMData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package proxy.examples.atm;

/**
* Created by luisburgos on 21/09/15.
*/
public interface GetATMData {
public int getCashInMachine();
}
20 changes: 20 additions & 0 deletions src/proxy/examples/images/ClientImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package proxy.examples.images;

/**
* Created by luisburgos on 21/09/15.
*/
public class ClientImage {

public static void main(String[] args) {

Image image = new ProxyImage("img_10.jpg");

//image will be loaded from disk
image.display();
System.out.println("");

//image will NOT be loaded from disk
image.display();
}

}
8 changes: 8 additions & 0 deletions src/proxy/examples/images/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package proxy.examples.images;

/**
* Created by luisburgos on 21/09/15.
*/
public interface Image {
public void display();
}
23 changes: 23 additions & 0 deletions src/proxy/examples/images/ProxyImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package proxy.examples.images;

/**
* Created by luisburgos on 21/09/15.
*/
public class ProxyImage implements Image {

private RealImage realImage;
private String imageFileName;

public ProxyImage(String fileName){
this.imageFileName = fileName;
}

@Override
public void display() {
if(realImage == null){
realImage = new RealImage(imageFileName);
}
realImage.display();
}

}
24 changes: 24 additions & 0 deletions src/proxy/examples/images/RealImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package proxy.examples.images;

/**
* Created by luisburgos on 21/09/15.
*/
public class RealImage implements Image {

private String imageFileName;

public RealImage(String imageFileName){
this.imageFileName = imageFileName;
loadFromDisk(imageFileName);
}

@Override
public void display() {
System.out.println("Displaying " + imageFileName);
}

private void loadFromDisk(String imageFileName){
System.out.println("Loading " + imageFileName);
}

}

0 comments on commit 365f40e

Please sign in to comment.