Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Tutorial: Introduction to Object-Oriented Programming

by aufflick (Deacon)
on Jul 30, 2004 at 02:26 UTC ( #378576=note: print w/ replies, xml ) Need Help??


in reply to Re: Tutorial: Introduction to Object-Oriented Programming
in thread Tutorial: Introduction to Object-Oriented Programming

I have been bitten by exactly the bug you describe to argue!

As mentioned elsewhere in the comments on your post, the only realy problem with your implementation of accessors is code maintenance - you need to add each get and set and then remember to add each store to the destroyer. I bet a lot of memory leaks would appear by forgetting to do this.

A comment by fruiture suggests a single data repository in the parent object with single get and set methods that take attribute names, but that implementation uses a hash internally and leaves you open to the same problem. It does, however, address both maintenance issues.

The same comment also points out that by avoiding a hash you lose the ability to use Data::Dumper to debug your objects easily.

You could use this repository idea, but have a hash in your object specifying the name and type of each of the attributes, and run a check on every get and set call. As a bonus, you could also use this hash to drive data validation by specifying a data type and/or validator sub - the set function could then optionally run a data validation of requested.


Comment on Re^2: Tutorial: Introduction to Object-Oriented Programming
Re^3: Tutorial: Introduction to Object-Oriented Programming
by adrianh (Chancellor) on Jul 30, 2004 at 11:43 UTC
    As mentioned elsewhere in the comments on your post, the only realy problem with your implementation of accessors is code maintenance - you need to add each get and set and then remember to add each store to the destroyer. I bet a lot of memory leaks would appear by forgetting to do this.

    See Class::InsideOut - yet another riff on inside out objects. for one way to avoid the chore of maintaining a DESTROY method.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://378576]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-11-26 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls