I am trying to create a flyweight object in Java. I worked with a similar concept in Objective-C (Singleton Classes in Objective-C // I believe this is the same thing).
I am trying to find a workbook or example or explanation on the Internet to learn how to create a flying object and use it, but I searched on Google and I can not find anything descent. I went through 10 pages and they basically all plagiarized from one website that just explains the concept. I understand the concept - I need something to help me / teach me how to implement it in Java.
Does anyone have any suggestions / tutorials?
Thank!
Java.
EDIT, OP :
, - , -, .
Wiki, CoffeeFlavorFactory CoffeeFlavor ( Flavor). , .
CoffeeFlavorFactory
CoffeeFlavor
public static void main(String[] args) { flavorFactory = new CoffeeFlavorFactory(); CoffeeFlavor a = flavorFactory.getCoffeeFlavor("espresso"); CoffeeFlavor b = flavorFactory.getCoffeeFlavor("espresso"); CoffeeFlavor c = flavorFactory.getCoffeeFlavor("espresso"); // This is comparing the reference value, not the contents of the objects if (a == b && b == c) System.out.println("I have three references to the same object!"); }
, ...
, (, CoffeeFlavors) (CoffeeOrders), . . , CoffeeOrders .
Orders , , "CoffeeOrderFactory", factory Flavors. , - Flavor. , CoffeeFlavor, , , .
?
. , .
. - :
. , "A" "A" . -
public Node add(String key){ Node node = nodes.get(key); if (null == node){ node = new Node(key); nodes.put(key, node); } return node; }
, .
, Java.
"java.lang.Character" flyweight US-ASCII: . java.lang.Character $CharacterCache, Character.valueOf()