An extremely good link indeed!
Actually the code examples given there support (IMHO) what I wrote in Re^2: Doubt about fly-weight objects., i.e. that the aspect that is mostly stressed is that of caching. But then again, it wasn't much touched upon in all of the previous examples of flyweight objects I had seen.
This actually raises in me a related question: if it's only for caching, can't one still obtain it with a lexical hash with "standard" objects? I mean, something a' la:
{
my %seen;
sub new {
my $class = shift;
my ($this, $value)=@_;
my $id = unique_id $this, $value;
$seen{$id} ||= bless { THIS => $this,
VALUE => $value }, $class;
}
# Suitable DERSTROY here...
}
In other words, the two concepts, i.e. that of caching and that of storing the actual object's data in package lexical "outside" of the object itself are mostly orthogonal. Aren't they? |