Reformat rest of the design patterns - Issue #224
This commit is contained in:
@ -2,30 +2,30 @@ package com.iluwatar.proxy;
|
||||
|
||||
/**
|
||||
*
|
||||
* A proxy, in its most general form, is a class functioning as an interface to something else.
|
||||
* The proxy could interface to anything: a network connection, a large object in memory, a file,
|
||||
* or some other resource that is expensive or impossible to duplicate. In short, a proxy is a
|
||||
* wrapper or agent object that is being called by the client to access the real serving object
|
||||
* behind the scenes.
|
||||
* A proxy, in its most general form, is a class functioning as an interface to something else. The
|
||||
* proxy could interface to anything: a network connection, a large object in memory, a file, or
|
||||
* some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper
|
||||
* or agent object that is being called by the client to access the real serving object behind the
|
||||
* scenes.
|
||||
* <p>
|
||||
* The Proxy design pattern allows you to provide an interface to other objects by creating a
|
||||
* wrapper class as the proxy. The wrapper class, which is the proxy, can add additional
|
||||
* The Proxy design pattern allows you to provide an interface to other objects by creating a
|
||||
* wrapper class as the proxy. The wrapper class, which is the proxy, can add additional
|
||||
* functionality to the object of interest without changing the object's code.
|
||||
* <p>
|
||||
* In this example the proxy ({@link WizardTowerProxy}) controls access to the actual object
|
||||
* ({@link WizardTower}).
|
||||
* In this example the proxy ({@link WizardTowerProxy}) controls access to the actual object (
|
||||
* {@link WizardTower}).
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
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"));
|
||||
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"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,15 +7,15 @@ package com.iluwatar.proxy;
|
||||
*/
|
||||
public class Wizard {
|
||||
|
||||
private String name;
|
||||
private String name;
|
||||
|
||||
public Wizard(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public Wizard(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.proxy;
|
||||
*/
|
||||
public class WizardTower {
|
||||
|
||||
public void enter(Wizard wizard) {
|
||||
System.out.println(wizard + " enters the tower.");
|
||||
}
|
||||
public void enter(Wizard wizard) {
|
||||
System.out.println(wizard + " enters the tower.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,17 +7,17 @@ package com.iluwatar.proxy;
|
||||
*/
|
||||
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
|
||||
public void enter(Wizard wizard) {
|
||||
if (numWizards < NUM_WIZARDS_ALLOWED) {
|
||||
super.enter(wizard);
|
||||
numWizards++;
|
||||
} else {
|
||||
System.out.println(wizard + " is not allowed to enter!");
|
||||
}
|
||||
}
|
||||
@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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ import com.iluwatar.proxy.App;
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user