Reverse Flyweight Pattern

implemented in the same way as the InstanceFlyweightPattern, but used for the opposite purpose. Anywhere one wishes to save memory in creating objects that map to real world structures, for example IO ports on an embedded system. Additionally, the ReverseFlyweightPattern allows the encapsulation of various fixed numbers, especially those fixed in hardware. A concrete example would be for objects representing computer monitors: the number of monitors is fixed at runtime, but can change between different computers, or even different runs of the same compiled instance of the program (or, with sufficiently PlugAndPlay monitors, possibly even while the program is running), so Singleton is clearly not appropriate. Alternatives are: Also, because the ReverseFlyweightPattern maps so closely over the SingletonPattern, one can use it to replace the singleton.
    #An embedded system has a certain number of IO pins, and each IOpin object maps to.
    #The state of each IOpin object for any single given pin number is exactly the same.
    #Essentially, this is an extension of the Singleton...
    class IOpin extends SystemObject?
        static Hashtable<Int, IOpin> cache;
        static def getInstance(Int pinNumber)
            IOpin _pin = null;
            if (!cache.has(pinNumber)) {
                 _pin = new IOpin(pinNumber);
                 cache.set(pinNumber, _pin);
            } else {
                 _pin = cache.get(pinNumber);
            return _pin;

private def Initialize(Int pinNumber) { Pinlookup p = Pinlookup.getInstance(); @address = p.getPinAddress(pinNumber) } def pinstate() { lvalue( set => def (Bool value) { Memory m = Memory.getInstance(); #get singleton m.poke(@address, value); #extern "C" { *(this->address) = value } return value }, get => def () { Memory m = Memory.getInstance(); return m.peek(@address) #extern "C" { return *(this->address) } } ) } }
Of course, this example doesn't HAVE to be a Reverse Flyweight, but this is the basic idea.
"An example is worth 1000 words..."

In this case, no. It tells me nothing. PatternForm would be appreciated.

OK, PatternForm has been added (GoF style), but some things are missing. Please help!

Much better, even in incomplete form.

View edit of September 8, 2013 or FindPage with title or text search