in reply to OO - inside-out or by means of a anonymous sub?
As I see things, the biggest advantage of using inside-out object is typo checking. $self->{attribute} becomes $attribute{$self}, which allows typos of attribute to be caught at compile time, rather than having them lead to weird problems at run-time. You mitigated this by providing accessors, but not by using closures.
Inside-out objects also provide data protection. If the attribute hash is a my variable, neither the main program nor other modules can access the attributes without using the accessors. Howver, in your closure code, anyone can do &{ $obj }("BALANCE", '1000000');. True, sanity checks could be added inside the closure, but inside-out objects could ban access to BALANCE completely.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: OO - inside-out or by means of a anonymous sub?
by xdg (Monsignor) on Jan 12, 2006 at 21:40 UTC | |
Re^2: OO - inside-out or by means of a anonymous sub?
by Roy Johnson (Monsignor) on Jan 12, 2006 at 16:26 UTC | |
by ikegami (Patriarch) on Jan 12, 2006 at 16:30 UTC |