From: "Rob Dixon" <[EMAIL PROTECTED]>
> You've created a package/class called 'Trainset' but decided not to
> instantiate it as an object. As James says, this is therefore no more
> than a namespace and could probably be more obviously coded as simple
> data items and subroutines in the 'main' namespace. At the very least,
> if you choose to have a bucket labelled 'Trainset' for all related
> subroutines and data, you should avoid writing methods for it. A call
> like
>
> Trainset->method()
>
> is hiding the more obvious and truthful
>
> Trainset::method()
>
> where there is no such thing as a 'Trainset' object.
Well ... it may make sense to use the method call format even if
there are no objects.
Inheritance works even with packages:
#
package A;
sub foo {print "foo called\n"}
package B;
@ISA = qw(A);
sub bar {print "bar called\n"};
package main;
B->bar();
B->foo();
B::bar();
B::foo();
__END__
This is actually used by File::Spec. (Though I think in that case the
desing is ... let's say ... strange.)
> As a secondary point, I think you're also confounding your learning
> process by considering object destruction before you have anything
> working. My advice is to get the basics going first, and then consider
> optimisation and memory conservation as a secondary chore. Certainly
> you should forget about implementing a DESTROY or 'delete' method
> until it proves necessary: the vast majority of Perl modules have no
> such method.
I think he just was told to create destroy methods in his Java/C#
class :-)
In either case ... just to reinforce your point ... in Perl you only
have to have a DESTROY method if you need to do some cleanup.
Returning handles to the system, closing connections, freeing memory
allocated outside the Perl memory space by the C part of your module,
updating some object counts and similar structures ...
Most often Perl will just do the right thing.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>