ok, let me explain what I mean.
$account = new Account;
then I can get the currency of the two countries,
$account->currency_us;
$account->currency_fr;

after I freeze the code, a new country jumps out, suppose i need
support Iraq, but now I can't use this,
$account->currency_iraq;
If I want to support this method, I have to modify the constructor
again to add the new country, but what I am looking for is the
solution that doesn't need to modify the constructor again.


On 7/19/06, Rob Dixon <[EMAIL PROTECTED]> wrote:
Ken Perl wrote:
>
> I find a difficulty when writing the constructor which may has dynamic
> and non fixed number of properties, say we want to construct a new
> class Account,
>
> package Account;
>
> sub new {
>  my $class = shift;
>  my $self = { currency_us=>undef,
>                     currency_fr =>undef,
>  };
>  bless $self, $class;
>  return $self;
> }
>
> If we want to create new object with more other contries' currency and
> don't want to modify the code, for example, get more other contries'
> name from database, how to write my constructor method and it can live
> with the dynamic database?

I'm unclear what you want. I don't see how you an do anything without modifying
the code. Do you mean you want to subclass Account?

Suppose you have a list of currencies in @currencies (I can't explain how to get
it there as I don't know where it's coming from) you can add these to your
object with:

   my @currencies = qw/ currency_uk currency_gr currency_sp /;

   @[EMAIL PROTECTED] = ();

Does this help at all?

Rob

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





--
perl -e 'print unpack(u,"62V5N\"FME;G\!E<FQ`9VUA:6PN8V]M\"[EMAIL PROTECTED]
")'

--
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