http://www.perlmonks.org?node_id=88116


in reply to Idea on a Base class API

First, I just want to say that I really enjoy this kind of post, and ++ dragonchild for doing this.

That said, I'm not sure I understand what the advantage is for a single get(), set() etc. method. If you're objecting to the additional work of defining all of the individual accessor/mutator methods, then there are implementation-based ways to eliminate this, like Class::Accessor, Class::Struct, and Class::MethodMaker.

I agree that it would be nice to have a facility for checking data types in members. Class::MethodMaker offers this for class types.

I'm a bit worried about the define_attributes() method. What is the expected behavior when it's called on a class where there are already instances out there? Does it suddenly alter the class behind the scenes? I think that could get pretty confusing.

I'd like to see a contract like this. However, my personal preference would be toward labeled get_foo() and set_foo() methods, since they're clearer to my eye. Plus, having a separate method for each member means that I can enforce any kind of consistency check I'd like without tacking on conditionals. If "foo" should be a multiple of pi, for example, and I want to have a method that tests this on sets, I don't want to have to override set() and insert an if ($name eq 'foo') { ... } statement, since avoiding confusing conditionals is one of the things that OO is supposed to help you avoid.

Anyway, just my thoughts on the matter.

stephen