in reply to Philosophy of a "new" method
But this probably connects to the same database every time, so it might make more sense to initiate the object with the database parameters straight away, i.e. set up the connection in the 'new' method so that the API becomes:my $da = DataAnalyzer->new(); $da->connect_to_db->($dsn); my $result_set = $da->run_analysis( %parameters_for_analysis );
Now the 'new' method does a bit moe work (set up the actual connection) but it seems to make more sense from the user's perspective.my $da = DataAnalyzer->new( $dsn ); my $result_set = $da->run_analysis( %parameters_for_analysis );
Whether or not you use an '_init' method is really just matter of style: it certainly helps to de-clutter the 'new' method itself and keep it short in cases where a lot of setting-up has to be done.my $result_set = DataAnalyzer->new( $dsn, \%parameters_for_analysis ) +;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Philosophy of a "new" method
by JavaFan (Canon) on Feb 04, 2011 at 17:23 UTC | |
by tospo (Hermit) on Feb 07, 2011 at 09:34 UTC | |
by JavaFan (Canon) on Feb 07, 2011 at 15:26 UTC | |
by tospo (Hermit) on Feb 09, 2011 at 10:37 UTC |