Java fly examples

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!

+5
source share
5 answers

Java.

EDIT, OP :

, - , -, .

Wiki, CoffeeFlavorFactory CoffeeFlavor ( Flavor). , .

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!");
}
+3

, ...

, (, CoffeeFlavors) (CoffeeOrders), . . , CoffeeOrders .

Orders , , "CoffeeOrderFactory", factory Flavors. , - Flavor. , CoffeeFlavor, , , .

?

+1

. , .

  • A: C E
  • B: D C
  • C: E
  • A: B

. - :

  • A: B C E
  • B: C D
  • C: E

. , "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;
}

, .

+1

, Java.

0

"java.lang.Character" flyweight US-ASCII: . java.lang.Character $CharacterCache, Character.valueOf()

0

All Articles