getter setter and database



suppose I have a table person with following columns, name, age,
salary. If use OOP to write a class like this,
package Person;
sub new{
$class=shift;
my $self = {};
$self->{_name} = undef;
$self->{_age} = undef;
$self->{_salary}= undef;
bless ($self,$class);
return $self;
}

#accessor method for name
sub name {
my $self = shift;
my $name = shift;
$self->{_name} = $name if defined($name);
return $self->{_name};
}

My question is, should I query/update the table at the same time in
above accessor method? If not, what's the best practice?

.



Relevant Pages

  • Re: Simple OOPs related query.
    ... sub speak { ... $class = shift; ... You should add my's, an explicit return, and make sure a space follows the ... Finally there is no good reason to put the entire package under a block. ...
    (perl.beginners)
  • Re: Packages and returning errors
    ... The perldoc function guide says about shift (which is ... "Shifts the first value of the array off and returns it, ... If an array of values are passed to a sub, ... Back to my package (which I am currently thinking might be out of my depth, ...
    (comp.lang.perl.misc)
  • Re: ClamAV
    ... 'ABSTRACT' => 'A simple interface to the Clam Anti-Virus system', ... sub MY::test { ... package MY; ... my $self = shift; ...
    (comp.lang.perl.modules)
  • Re: Why isnt shift the same as $_[0]?
    ... use warnings; ... > sub AUTOLOAD ... Ahem, you are using shift as a hash key, not calling shift on @_: ... package My::Base; ...
    (comp.lang.perl.misc)
  • Re: Threads and OO Question
    ... > " bless is not supported on shared references. ... sub increment { ... package MyPackage; ... my $class = shift; ...
    (comp.lang.perl.misc)