Hi,

I recently rewrote a program using OO techniques. Because my scripts usually do 
not exceed two hundred lines, I am not too familiar with OO design guidelines 
in Perl.

So while I got everything to work (with the help of Randal's "Learning Perl 
ORM"), I am unsure about the preferred way to do the following.

My program consists of a constructor class, methods to add data to a class 
instance and methods to display the instance data.

I currently use the data methods like so:

sub display_children {
    # displays subordinate pages
    my $self = shift;
    return '' unless $self->children();
    ...
}

sub children {
    # determines the subordinate pages, returning an anonymous AoH
    my $self = shift;
    ...
    $self->{children};
}

In other words, the display class calls the corresponding data class, returning 
the empty string if the latter does so, too.

I wonder if I should rather place calls to the data classes in the constructor 
method and base the return statement in the display class explicitly on the 
existence of appropriate data within the instance:

sub new {
    ...
    $self->children();
    ...
}

sub display_children {
    ...
    return '' unless $self->{children};
}

My second (related) question is: I currently invoke all the methods 
unconditionally, placing a conditional return statement early within each 
method:

return '' unless $self->{type} eq 'page';

While this makes the code outside the methods cleaner, I wonder if it would 
make a significant difference in performance if the calls to the methods 
contained all the conditions:

$self->children() if $self->{type} eq 'page';

Thanks in advance,

Jan
-- 
These are my principles and if you don't like them... well, I have others. - 
Groucho Marx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to