X Tutup
Skip to content

Commit 05cb408

Browse files
committed
Commented flyweight example.
1 parent 05d2129 commit 05cb408

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
/**
7+
*
8+
* The class that needs many objects.
9+
*
10+
*/
611
public class AlchemistShop {
712

813
List<Potion> topShelf;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Flyweight (PotionFactory) is useful when there is plethora of
6+
* objects (Potion). It provides means to decrease resource usage
7+
* by sharing object instances.
8+
*
9+
*/
310
public class App
411
{
512
public static void main( String[] args )

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Interface for objects.
6+
*
7+
*/
38
public interface Potion {
49

510
public void drink();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import java.util.EnumMap;
44

5+
/**
6+
*
7+
* Flyweight.
8+
*
9+
*/
510
public class PotionFactory {
611

712
private EnumMap<PotionType, Potion> potions;

0 commit comments

Comments
 (0)
X Tutup