X Tutup
Skip to content

Commit de784cf

Browse files
committed
iluwatar#107 Flyweight example JavaDoc
1 parent 25a2fc7 commit de784cf

File tree

7 files changed

+107
-73
lines changed

7 files changed

+107
-73
lines changed

flyweight/src/main/java/com/iluwatar/flyweight/App.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
*
55
* Flyweight pattern is useful when the program needs a huge amount of objects.
66
* It provides means to decrease resource usage by sharing object instances.
7-
*
8-
* In this example AlchemistShop has great amount of potions on its shelves.
9-
* To fill the shelves AlchemistShop uses PotionFactory (which represents
10-
* the Flyweight in this example). Internally PotionFactory holds a map
7+
* <p>
8+
* In this example {@link AlchemistShop} has great amount of potions on its shelves.
9+
* To fill the shelves {@link AlchemistShop} uses {@link PotionFactory} (which represents
10+
* the Flyweight in this example). Internally {@link PotionFactory} holds a map
1111
* of the potions and lazily creates new ones when requested.
12-
*
12+
* <p>
1313
* To enable safe sharing, between clients and threads, Flyweight objects must
1414
* be immutable. Flyweight objects are by definition value objects.
1515
*
1616
*/
1717
public class App {
1818

19+
/**
20+
* Program entry point
21+
* @param args command line args
22+
*/
1923
public static void main(String[] args) {
2024
AlchemistShop alchemistShop = new AlchemistShop();
2125
alchemistShop.enumerate();
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
package com.iluwatar.flyweight;
2-
3-
public class HealingPotion implements Potion {
4-
5-
@Override
6-
public void drink() {
7-
System.out.println("You feel healed. (Potion="
8-
+ System.identityHashCode(this) + ")");
9-
}
10-
11-
}
1+
package com.iluwatar.flyweight;
2+
3+
/**
4+
*
5+
* HealingPotion
6+
*
7+
*/
8+
public class HealingPotion implements Potion {
9+
10+
@Override
11+
public void drink() {
12+
System.out.println("You feel healed. (Potion="
13+
+ System.identityHashCode(this) + ")");
14+
}
15+
16+
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
package com.iluwatar.flyweight;
2-
3-
public class HolyWaterPotion implements Potion {
4-
5-
@Override
6-
public void drink() {
7-
System.out.println("You feel blessed. (Potion="
8-
+ System.identityHashCode(this) + ")");
9-
}
10-
11-
}
1+
package com.iluwatar.flyweight;
2+
3+
/**
4+
*
5+
* HolyWaterPotion
6+
*
7+
*/
8+
public class HolyWaterPotion implements Potion {
9+
10+
@Override
11+
public void drink() {
12+
System.out.println("You feel blessed. (Potion="
13+
+ System.identityHashCode(this) + ")");
14+
}
15+
16+
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
package com.iluwatar.flyweight;
2-
3-
public class InvisibilityPotion implements Potion {
4-
5-
@Override
6-
public void drink() {
7-
System.out.println("You become invisible. (Potion="
8-
+ System.identityHashCode(this) + ")");
9-
}
10-
11-
}
1+
package com.iluwatar.flyweight;
2+
3+
/**
4+
*
5+
* InvisibilityPotion
6+
*
7+
*/
8+
public class InvisibilityPotion implements Potion {
9+
10+
@Override
11+
public void drink() {
12+
System.out.println("You become invisible. (Potion="
13+
+ System.identityHashCode(this) + ")");
14+
}
15+
16+
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
package com.iluwatar.flyweight;
2-
3-
public class PoisonPotion implements Potion {
4-
5-
@Override
6-
public void drink() {
7-
System.out.println("Urgh! This is poisonous. (Potion="
8-
+ System.identityHashCode(this) + ")");
9-
}
10-
11-
}
1+
package com.iluwatar.flyweight;
2+
3+
/**
4+
*
5+
* PoisonPotion
6+
*
7+
*/
8+
public class PoisonPotion implements Potion {
9+
10+
@Override
11+
public void drink() {
12+
System.out.println("Urgh! This is poisonous. (Potion="
13+
+ System.identityHashCode(this) + ")");
14+
}
15+
16+
}
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
package com.iluwatar.flyweight;
2-
3-
public class StrengthPotion implements Potion {
4-
5-
@Override
6-
public void drink() {
7-
System.out.println("You feel strong. (Potion="
8-
+ System.identityHashCode(this) + ")");
9-
}
10-
}
1+
package com.iluwatar.flyweight;
2+
3+
/**
4+
*
5+
* StrengthPotion
6+
*
7+
*/
8+
public class StrengthPotion implements Potion {
9+
10+
@Override
11+
public void drink() {
12+
System.out.println("You feel strong. (Potion="
13+
+ System.identityHashCode(this) + ")");
14+
}
15+
}
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
package com.iluwatar.flyweight;
2-
3-
import org.junit.Test;
4-
5-
import com.iluwatar.flyweight.App;
6-
7-
public class AppTest {
8-
9-
@Test
10-
public void test() {
11-
String[] args = {};
12-
App.main(args);
13-
}
14-
}
1+
package com.iluwatar.flyweight;
2+
3+
import org.junit.Test;
4+
5+
import com.iluwatar.flyweight.App;
6+
7+
/**
8+
*
9+
* Application test
10+
*
11+
*/
12+
public class AppTest {
13+
14+
@Test
15+
public void test() {
16+
String[] args = {};
17+
App.main(args);
18+
}
19+
}

0 commit comments

Comments
 (0)
X Tutup