Commented flyweight example.

This commit is contained in:
Ilkka Seppala 2014-08-31 10:16:48 +03:00
parent 05d212959a
commit 05cb40897b
4 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,11 @@ package com.iluwatar;
import java.util.ArrayList;
import java.util.List;
/**
*
* The class that needs many objects.
*
*/
public class AlchemistShop {
List<Potion> topShelf;

View File

@ -1,5 +1,12 @@
package com.iluwatar;
/**
*
* Flyweight (PotionFactory) is useful when there is plethora of
* objects (Potion). It provides means to decrease resource usage
* by sharing object instances.
*
*/
public class App
{
public static void main( String[] args )

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* Interface for objects.
*
*/
public interface Potion {
public void drink();

View File

@ -2,6 +2,11 @@ package com.iluwatar;
import java.util.EnumMap;
/**
*
* Flyweight.
*
*/
public class PotionFactory {
private EnumMap<PotionType, Potion> potions;