Reverse Flyweight Patternimplemented in the same way as the InstanceFlyweightPattern, but used for the opposite purpose.
#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?
has(@address)
{
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.
**
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.
EditText of this page
(last edited September 8, 2013)
or FindPage with title or text search