On Wed, Oct 09, 2002 at 02:34:49PM -0500, James Edward Gray II wrote: > If I have an object and I want to increase it's functionality by > "upgrading/promoting" it to a subclass if certain conditions are met > during a method call, could/should I use something like: > > sub some_method { > my $self = $_[0]; > > # ... > > if (PROMOTE_CONDITION) { > $_[0] = Subclass->copy_constructor($self); > } > } > > That will change the reference in the calling code, right?
Right. > Any reason > I shouldn't do this? Not if you know what you are doing. Presumably your copy constructor is simply reblessing the object and maybe doing some initialisation. Be careful if your original object had a destructor. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]