Changed package naming across all examples.

This commit is contained in:
Ilkka Seppala
2015-05-31 11:55:18 +03:00
parent 703ebd3e20
commit 8524c75ba6
437 changed files with 1095 additions and 1402 deletions
@@ -0,0 +1,20 @@
package com.iluwatar.proxy;
/**
*
* Proxy (WizardTowerProxy) controls access to the actual object (WizardTower).
*
*/
public class App {
public static void main(String[] args) {
WizardTowerProxy tower = new WizardTowerProxy();
tower.enter(new Wizard("Red wizard"));
tower.enter(new Wizard("White wizard"));
tower.enter(new Wizard("Black wizard"));
tower.enter(new Wizard("Green wizard"));
tower.enter(new Wizard("Brown wizard"));
}
}
@@ -0,0 +1,16 @@
package com.iluwatar.proxy;
public class Wizard {
private String name;
public Wizard(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
@@ -0,0 +1,14 @@
package com.iluwatar.proxy;
/**
*
* The object to be proxyed.
*
*/
public class WizardTower {
public void enter(Wizard wizard) {
System.out.println(wizard + " enters the tower.");
}
}
@@ -0,0 +1,23 @@
package com.iluwatar.proxy;
/**
*
* The proxy controlling access to WizardTower.
*
*/
public class WizardTowerProxy extends WizardTower {
private static final int NUM_WIZARDS_ALLOWED = 3;
private int numWizards;
@Override
public void enter(Wizard wizard) {
if (numWizards < NUM_WIZARDS_ALLOWED) {
super.enter(wizard);
numWizards++;
} else {
System.out.println(wizard + " is not allowed to enter!");
}
}
}