#107 JavaDoc for Proxy example
This commit is contained in:
parent
0db6581cfd
commit
4d08d16bb1
@ -1,20 +1,20 @@
|
|||||||
package com.iluwatar.proxy;
|
package com.iluwatar.proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Proxy (WizardTowerProxy) controls access to the actual object (WizardTower).
|
* Proxy ({@link WizardTowerProxy}) controls access to the actual object ({@link WizardTower}).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
WizardTowerProxy tower = new WizardTowerProxy();
|
WizardTowerProxy tower = new WizardTowerProxy();
|
||||||
tower.enter(new Wizard("Red wizard"));
|
tower.enter(new Wizard("Red wizard"));
|
||||||
tower.enter(new Wizard("White wizard"));
|
tower.enter(new Wizard("White wizard"));
|
||||||
tower.enter(new Wizard("Black wizard"));
|
tower.enter(new Wizard("Black wizard"));
|
||||||
tower.enter(new Wizard("Green wizard"));
|
tower.enter(new Wizard("Green wizard"));
|
||||||
tower.enter(new Wizard("Brown wizard"));
|
tower.enter(new Wizard("Brown wizard"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
package com.iluwatar.proxy;
|
package com.iluwatar.proxy;
|
||||||
|
|
||||||
public class Wizard {
|
/**
|
||||||
|
*
|
||||||
private String name;
|
* Wizard
|
||||||
|
*
|
||||||
public Wizard(String name) {
|
*/
|
||||||
this.name = name;
|
public class Wizard {
|
||||||
}
|
|
||||||
|
private String name;
|
||||||
@Override
|
|
||||||
public String toString() {
|
public Wizard(String name) {
|
||||||
return name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
package com.iluwatar.proxy;
|
package com.iluwatar.proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The proxy controlling access to WizardTower.
|
* The proxy controlling access to the {@link WizardTower}.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WizardTowerProxy extends WizardTower {
|
public class WizardTowerProxy extends WizardTower {
|
||||||
|
|
||||||
private static final int NUM_WIZARDS_ALLOWED = 3;
|
private static final int NUM_WIZARDS_ALLOWED = 3;
|
||||||
|
|
||||||
private int numWizards;
|
private int numWizards;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter(Wizard wizard) {
|
public void enter(Wizard wizard) {
|
||||||
if (numWizards < NUM_WIZARDS_ALLOWED) {
|
if (numWizards < NUM_WIZARDS_ALLOWED) {
|
||||||
super.enter(wizard);
|
super.enter(wizard);
|
||||||
numWizards++;
|
numWizards++;
|
||||||
} else {
|
} else {
|
||||||
System.out.println(wizard + " is not allowed to enter!");
|
System.out.println(wizard + " is not allowed to enter!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
package com.iluwatar.proxy;
|
package com.iluwatar.proxy;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.iluwatar.proxy.App;
|
import com.iluwatar.proxy.App;
|
||||||
|
|
||||||
public class AppTest {
|
/**
|
||||||
|
*
|
||||||
@Test
|
* Application test
|
||||||
public void test() {
|
*
|
||||||
String[] args = {};
|
*/
|
||||||
App.main(args);
|
public class AppTest {
|
||||||
}
|
|
||||||
}
|
@Test
|
||||||
|
public void test() {
|
||||||
|
String[] args = {};
|
||||||
|
App.main(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user