File tree Expand file tree Collapse file tree 6 files changed +84
-0
lines changed
src/main/java/com/iluwatar Expand file tree Collapse file tree 6 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 2929 <module >decorator</module >
3030 <module >facade</module >
3131 <module >flyweight</module >
32+ <module >proxy</module >
3233 </modules >
3334
3435<build >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <project xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" >
4+ <modelVersion >4.0.0</modelVersion >
5+ <parent >
6+ <groupId >com.iluwatar</groupId >
7+ <artifactId >java-design-patterns</artifactId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <groupId >com.iluwatar</groupId >
11+ <artifactId >proxy</artifactId >
12+ <version >1.0-SNAPSHOT</version >
13+ <name >proxy</name >
14+ <url >http://maven.apache.org</url >
15+ <dependencies >
16+ <dependency >
17+ <groupId >junit</groupId >
18+ <artifactId >junit</artifactId >
19+ <version >3.8.1</version >
20+ <scope >test</scope >
21+ </dependency >
22+ </dependencies >
23+ </project >
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class App
4+ {
5+ public static void main ( String [] args )
6+ {
7+
8+ WizardTowerProxy tower = new WizardTowerProxy ();
9+ tower .enter (new Wizard ("Red wizard" ));
10+ tower .enter (new Wizard ("White wizard" ));
11+ tower .enter (new Wizard ("Black wizard" ));
12+ tower .enter (new Wizard ("Green wizard" ));
13+ tower .enter (new Wizard ("Brown wizard" ));
14+
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class Wizard {
4+
5+ private String name ;
6+
7+ public Wizard (String name ) {
8+ this .name = name ;
9+ }
10+
11+ @ Override
12+ public String toString () {
13+ return name ;
14+ }
15+
16+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class WizardTower {
4+
5+ public void enter (Wizard wizard ) {
6+ System .out .println (wizard + " enters the tower." );
7+ }
8+
9+ }
Original file line number Diff line number Diff line change 1+ package com .iluwatar ;
2+
3+ public class WizardTowerProxy extends WizardTower {
4+
5+ private static final int NUM_WIZARDS_ALLOWED = 3 ;
6+
7+ private int numWizards ;
8+
9+ @ Override
10+ public void enter (Wizard wizard ) {
11+ if (numWizards < NUM_WIZARDS_ALLOWED ) {
12+ super .enter (wizard );
13+ numWizards ++;
14+ } else {
15+ System .out .println (wizard + " is not allowed to enter!" );
16+ }
17+ }
18+
19+ }
You can’t perform that action at this time.
0 commit comments