Labels

algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

Flyweight


Share objects when they are common some common examples are from the JDK
Integer and String objects
The object is restricted to be created through the factory and the object is shared.
/*

 public static Integer valueOf(int i) {
        assert IntegerCache.high >= 127;
        if (i >= IntegerCache.low && i <= IntegerCache.high)
            return IntegerCache.cache[i + (-IntegerCache.low)];
        return new Integer(i);
    }
*/

No comments:

Post a Comment

Search 24 Bytes