in reply to OOP By Any Other Name
You are using two techniques. I don't know which you are asking about.
You are using closures to privatise attributes. (Contrary to what others have said, you don't have "a closure". Each of your methods are closures.) I don't know if using closures for this purpose has a name.
You have per-object methods instead of classes. JavaScript uses this. It's called Prototype-based programming. Except you don't actually support prototypes.
By the way, why create %internal at all?
Or evensub new_counter { my ($start) = @_; my $count = $start; return { add => sub { my ($value) = @_; $count += $value; }, get => sub { return $count; }, }; }
sub new_counter { my ($count) = @_; ... }
|
|---|