in reply to Re: OO manner of accessing static variables in a subclass?
in thread OO manner of accessing static variables in a subclass?
Ken, thank you so much for your response. You've given me a lot of homework, which I really appreciate. :) I've been using OO code for a long time of course, but I'm new to writing it, and this is exactly the kind of learning experience that I'm after.
Your comments about Exporter are spot on, I have been experimenting with a lot of stuff, and copied and pasted various examples I came across until I had something that worked, then like all good (lazy) programmers I stopped fussing with it. However, I've now got a pretty functional framework for my project, which I now want to start cleaning up and doing things right.
In regards to your comments about the child using the parent, I was reading about 'parent' today, so that's a recent addition. I'm just as happy without it. I get your point about the naming, but the subclass is not really "general purpose" data. I originally thought about a "parallel" package, like Foo_Data, but unless I'm missing something I'm not sure that would solve my data access "issues." I'm also not sure of the propriety of distributing a package that's structured like that, but if it's Ok to do, and it's the right solution, I'm not opposed to doing it.
I'm sort of partial to BEGIN blocks, but I'll read your references. I'd like a way for the user to retrieve the versions, but again, I'll read your references. The date-based version on the data module is a conscious choice, as I'd like an easy reference to when the module was generated.
Your guess is correct regarding $self->get_attr vs. $self->{attr}. I personally find the latter a lot easier to use, but I also don't want to open any more access to the data structures than really necessary. One question occurred to me though, how important is that issue when we're dealing with data that is being parsed out for use by the user? For instance, I have a method that does the actual parsing, and it places the data in a hash. I created methods so that the user can access the data the proper way, but what's to stop them from digging into the code and accessing the hash directly? I did a lot of reading on Perl modules' implied contract with the user that they don't do such things, and if they do, they are on their own if I change the data structure. So if that's the answer, I'm Ok with it.
Sorry about the furry/fluffy thing, I was just trying to have some fun with my sample code. :) Your restructure of the Data module, and the corresponding manner of access are both clear, thanks! And I like simple, it's easier to see what you're doing and how. One question, why the curly braces in the grep in is_furry? Just a style issue? Or does it have a utility in this context that I'm not seeing?
And one more question, and I hope I'm not missing an obvious reason why it's a silly one. :) Is there any benefit to the way that you've set it up (methods that return the data in the Data module, and methods that use the data in the parent) vs. what Athanasius proposed in putting the data and the methods that use the data both in the same package? On one hand I can see an argument for keeping the data module as clean and reusable as possible. OTOH, looking at how I actually use the data, Athanasius' concept is attractive. But I'm still wondering why I couldn't simply call $Monks::Data::->am_i_furry from the main package.
Again, thanks all for your time and effort in helping me learn this stuff. :)
|
|---|